Save image under a different name

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, helmut, xnview

Post Reply
Zuldek
Posts: 12
Joined: Fri Jul 05, 2019 1:24 pm

Save image under a different name

Post by Zuldek »

Code: Select all

nconvert -ratio -resize 325 -overwrite output.jpeg
I compress the image in width in proportion. How to save the image under a different name?
cday
XnThusiast
Posts: 3973
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Save image under a different name

Post by cday »

Zuldek wrote: Fri Jul 05, 2019 1:28 pm
I compress the image in width in proportion. How to save the image under a different name?

Code: Select all

-o filename       : Output filename
              Use # to specify position of numeric enumerator
              Use % to specify source filename
              Use $ to specify full source pathname
              Use $$ to specify source folder name
              Use $EXIF:DateModified[date format] to specify EXIF date modified
              Use $EXIF:DateTaken[date format] to specify EXIF date taken
									Date format: Please check documentation of strftime
          -out format       : Output format name

You have created a copy of the help file?
Zuldek
Posts: 12
Joined: Fri Jul 05, 2019 1:24 pm

Re: Save image under a different name

Post by Zuldek »

Code: Select all

** NCONVERT v7.25 (c) 1991-2019 Pierre-E Gougelet (Jan 15 2019/12:05:55) **
        Version for Windows Xp/Vista/7 x64  (All rights reserved)
** This is freeware software (for non-commercial use)


output.jpeg : Success
    Format               : JPEG TrueColor (v1.2)
    Name                 : jpeg
    Compression          : JPEG
    Width                : 1280
    Height               : 720
    Components per pixel : 3
    Bits per component   : 8
    Depth                : 24
    # colors             : 16777216
    Color model          : RGB
    Bytes Per Plane      : 3840
    Orientation          : Top Left
    Xdpi                 : Not set
    Ydpi                 : Not set
    Page(s)              : 1
    Comment              : Lavc57.107.100
New to bat programming, tell me how to get the width

Code: Select all

    Width                : 1280

Code: Select all

for /f  "tokens=1* delims=:" %%a in ('nconvert -info output.jpeg ^|find "[11]"') do (
	echo  %%a
    echo %%b
)
I tried a lot of options, nothing comes out. I don't know what to do
cday
XnThusiast
Posts: 3973
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Save image under a different name

Post by cday »

Zuldek wrote: Fri Jul 05, 2019 2:31 pmI tried a lot of options, nothing comes out. I don't know what to do
I don't know either, and it unlikely from past experience that anyone else will post a solution... :(

It is possible to write the image info to a text file, so possibly there is a way to parse that file to place a specific value into a variable that can then be used for further processing, for example for comparison with a specified value. That is a need I have sometimes identified myself.

I should make clear that my knowledge is limited to NConvert, plus some limited cmd.exe ['DOS'] which I have used to create batch files .bat. I answer NConvert posts because no-one else does, and from the code you posted above you have a deeper knowledge than I do. You could try requesting help on one or two of the general programming forums, and if you obtain any useful information please be sure to send me a link!

I may, however, start a new thread asking directly about extracting image information into a variable, in the hope that Pierre may respond. :?:

Edit:

I think ImageMagick may possibly provide a possible solution...
Zuldek
Posts: 12
Joined: Fri Jul 05, 2019 1:24 pm

Re: Save image under a different name

Post by Zuldek »

Code: Select all

nconvert -ratio -resize shortest 180 -o output.jpg -out output222222.jpg
Cannot change the name of the convection image when saving
cday
XnThusiast
Posts: 3973
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Save image under a different name

Post by cday »

Zuldek wrote: Fri Jul 05, 2019 5:47 pm

Code: Select all

nconvert -ratio -resize shortest 180 -o output.jpg -out output222222.jpg
Cannot change the name of the convection image when saving

Code: Select all

-out format       : Output format name
I think, looking quickly, that you need to add the format.
Zuldek
Posts: 12
Joined: Fri Jul 05, 2019 1:24 pm

Re: Save image under a different name

Post by Zuldek »

Code: Select all

nconvert -ratio -resize shortest 180 -o output.jpg -out format output222222.jpg
I tried it and it does not come out (((
cday
XnThusiast
Posts: 3973
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Save image under a different name

Post by cday »

Zuldek wrote: Fri Jul 05, 2019 6:20 pm

Code: Select all

nconvert -ratio -resize shortest 180 -o output.jpg -out format output222222.jpg
I tried it and it does not come out (((

You need to replace 'format' with the actual format, JPEG, I think it should work then, but I can't check it conveniently on my Linux laptop...
1x1
Posts: 6
Joined: Sat Aug 15, 2020 3:01 am

Re: Save image under a different name

Post by 1x1 »

I'm little late but I post thought, for in case that you havent found a batch solution...

Here are some example to direct request the result of nconvert and fill some var :

Code: Select all

@echo off

::Example 1 - request image width
for /f "tokens=2 delims=: " %%a in ('nconvert -info "img.jpg" ^| findstr /C:"Width"') do set WIDTH=%%a
echo Example 1 - The image width is %WIDTH%

::Example 2 - request jpeg format description
for /f "tokens=2 delims=:" %%a in ('nconvert -help ^| findstr /C:"[jpeg"') do set DESCRIPT=%%a
::trim space of the var
for /f "tokens=* eol= " %%t in ("%DESCRIPT%") do set DESCRIPT=%%t
echo Example 2 - The image format description is %DESCRIPT%

::Example 3 - request image multiple infos
setlocal enabledelayedexpansion
set count=1
for /f "tokens=2 delims=:" %%a in ('nconvert -info "img.jpg"') do (
    set VAR!count!=%%a
    set /a count=!count!+1
)

echo.
echo Example 3 - Print all infos values found:
for /L %%i in (1, 1, !count!) do (
    if %%i lss !count! (echo !VAR%%i!)
)

::trim space of selected vars
for /f "tokens=* eol= " %%t in ("%VAR3%") do set VAR3=%%t
for /f "tokens=* eol= " %%t in ("%VAR5%") do set VAR5=%%t
for /f "tokens=* eol= " %%t in ("%VAR6%") do set VAR6=%%t
for /f "tokens=* eol= " %%t in ("%VAR7%") do set VAR7=%%t
for /f "tokens=* eol= " %%t in ("%VAR11%") do set VAR11=%%t
for /f "tokens=* eol= " %%t in ("%VAR12%") do set VAR12=%%t

echo.
echo Example 3 - Var selection:
echo %VAR3%     &REM format
echo %VAR5%     &REM compression
echo %VAR6%     &REM width
echo %VAR7%     &REM height
echo %VAR11%    &REM color nb
echo %VAR12%    &REM color type      &REM is just for end line comment

endlocal
Just place nconvert.exe and img.jpg in the same dir of the bat file to view the correct results.
Dont hesitate asking me if you want more explain, but I'm not a pro at all in batch...
I found batch hard, and too restricted, I suggest you using another more easy language like PowerShell/Python/Perl/PHP
Me I use PHP that I very well know.

If you want continue with batch :
The main "hard" changes you will have to adapt to your results are with tokens= and delims=
The tokens are the text parts number that will fall in the variables like %%a %%b, it will found these parts number depending on the delimiters you put in delims.

For the irreducible batch user, I suggest combining it with some of the GNUWin32 tools, like grep/regex http://gnuwin32.sourceforge.net/packages.html

Good luck cday ;) ...oops you are on linux :D
cday
XnThusiast
Posts: 3973
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Save image under a different name

Post by cday »

1x1 wrote: Wed Aug 19, 2020 2:33 am I'm a little late but I post in case that you haven't found a batch solution...

Good luck cday ;)
Thank you very much for posting your solution for obtaining image parameters from NConvert -info output in a way that enables them to be used as variables in subsequent code; it is a solution to zuldek's problem above, but a similar need has sometimes arisen in other contexts... :D

...oops you are on linux :D
I am normally in Linux but can boot into Windows 10 if necessary, but I prefer not to firstly as it disrupts my workflow, and secondly simply because it is Windows 10... :wink:

I should invest some time in learning how to run NConvert under Linux.
Post Reply