Using different input and output directories

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

Moderators: XnTriq, xnview

agdabn
Posts: 10
Joined: Tue Mar 02, 2021 9:30 am

Using different input and output directories

Post by agdabn »

Hi, everybody
I use an online translator
Please help me write a bat file.
I have the necessary settings for nconvert:

nconvert -ratio -rtype lanczos -rflag decr -rflag orient -resize 500 500 -sharpen 50 -dpi 96 -clean 95

I need to start the bat file to convert all the files in the folder:

\\srv-10\imgkatalog\ImagePriceFull\

to the folder at:

\\srv-08\exchange\Imagsmall\
cday
XnThusiast
Posts: 2942
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Using different input and output directories

Post by cday »

Using Windows CMD?

The input files must be the last (right-most) term in the command line so, for example:

Code: Select all

... D:\Input\*.jpg
For the output term please see this thread.
agdabn
Posts: 10
Joined: Tue Mar 02, 2021 9:30 am

Re: Using different input and output directories

Post by agdabn »

Yes, I use Windows CMD
Thanks for the link, I've seen this forum thread.
But I still can't figure out how to make a bat file
cday
XnThusiast
Posts: 2942
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Using different input and output directories

Post by cday »

agdabn wrote: Tue Mar 02, 2021 12:36 pm But I still can't figure out how to make a bat file
Simple: create a text file containing your code, then save it with a .bat extension, or do I misunderstand?

It can be useful when testing to add a 'Pause' instruction on a new line after the command line, then the CMD window remains open and it is possible to read the terminal output, although when there is an error that may not actually be very helpful :wink:.

Be careful when working and editing code, not to confuse similar files with .txt and .bat extensions.

The small utility 'Open with notepad' may be worth installing, it is then possible to open .bat files directly in Notepad, so that any corresponding .txt files can be deleted reducing the risk of possible confusion.
agdabn
Posts: 10
Joined: Tue Mar 02, 2021 9:30 am

Re: Using different input and output directories

Post by agdabn »

cday wrote: Tue Mar 02, 2021 12:53 pm
agdabn wrote: Tue Mar 02, 2021 12:36 pm But I still can't figure out how to make a bat file
Simple: create a text file containing your code, then save it with a .bat extension, or do I misunderstand?

It can be useful when testing to add a 'Pause' instruction on a new line after the command line, then the CMD window remains open and it is possible to read the terminal output, although when there is an error that may not actually be very helpful :wink:.

Be careful when working and editing code, not to confuse similar files with .txt and .bat extensions.

The small utility 'Open with notepad' may be worth installing, it is then possible to open .bat files directly in Notepad, so that any corresponding .txt files can be deleted reducing the risk of possible confusion.
Thanks

I'm talking about what I need to write inside the bat file
I wrote:

Code: Select all

@chcp 1251
@for /R D:\images_input\ %%A in (*.jpg *.jpeg)  do "d:\D:\NConvert\nconvert" -ratio -rtype lanczos -rflag decr -rflag orient -resize 500 500  -sharpen 50 -dpi 96 -clean 95 "%%A" D:\images_output\*.jpg
But it doesn't work
cday
XnThusiast
Posts: 2942
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Using different input and output directories

Post by cday »

The problem is possibly in the detail design (syntax) of your For loop, however to be sure it would be best to test just the basic NConvert code required to perform what you need on one directory or file, then you can be sure that any remaining problem is with the For loop. You want to be sure that the NConvert code you need runs outside the loop, do you have code that does that?

I have only quite limited experience at the command line, and find For loops difficult: usually a fair amount of 'trial and error' is necessary.

You could do an online search for 'CMD for /R loop' or something similar, and then compare examples with your code.

Here is one result from a quick search: For /R

If necessary, you could then post on one of the general programming forums, you may see some in the above search, this is one example StackOverflow.
agdabn
Posts: 10
Joined: Tue Mar 02, 2021 9:30 am

Re: Using different input and output directories

Post by agdabn »

Thanks, I did a little bit of For /r work.

When I use XnConvert, the conversion result is fine with me.
Then I click on the "Export for NConvert" button.
I get the text that I paste into the bat file.
After executing the bat file, the conversion takes place, but the image is different from XnConvert
Why?
cday
XnThusiast
Posts: 2942
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Using different input and output directories

Post by cday »

agdabn wrote: Tue Mar 02, 2021 9:18 pm Thanks, I did a little bit of For /r work.

When I use XnConvert, the conversion result is fine with me.
Then I click on the "Export for NConvert" button.
I get the text that I paste into the bat file.
I'm glad you have found a solution!

After executing the bat file, the conversion takes place, but the image is different from XnConvert
In what respect are the images different, the visual quality, the file size or something else?

The NConvert code has no JPEG quality (-q) setting, but the default value is currently 85, I think.

If necessary, could you show your latest code and upload an example of the XnConvert and the NConvert files?
agdabn
Posts: 10
Joined: Tue Mar 02, 2021 9:30 am

Re: Using different input and output directories

Post by agdabn »

Hi.
I have attached four images.
Original.jpg (297kb) is the original image
is the original image
is the original image
Resize_NConvert.jpg (409kb) - this is converted by NConvert
this is converted by NConvert
this is converted by NConvert
Resize_XnConvert.jpg (15) - this is converted by XnConvert
this is converted by XnConvert
this is converted by XnConvert
Risize_XnConvert.jpg (14.97 KiB) Viewed 517 times
Settings_XnConvert.jpg (73kb) - XnConvert conversion settings
XnConvert conversion settings
XnConvert conversion settings
I convert in the same folder where the image is located, replacing the original
To convert using NConvert, I used the command:

Code: Select all

@chcp 1251
@for %%A in (D:\images_Test\*.jp*)  do "D:\NConvert\nconvert" -ratio -rtype lanczos -rflag decr -rflag orient -resize 500 500 -sharpen 50 -dpi 96 -clean 95 "%%A"
cday
XnThusiast
Posts: 2942
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Using different input and output directories

Post by cday »

The main difference is that the NConvert image pixel dimensions are not as expected, 500 x 500px?

Also the JPEG quality of the XnConvert image is 70, but the quality of the NConvert image is 85, the default value, as you don't have a -q 70 term.

Are there any other relevant differences?
agdabn
Posts: 10
Joined: Tue Mar 02, 2021 9:30 am

Re: Using different input and output directories

Post by agdabn »

Yes, that's right.
The image size is not 500x500
And the weight of XnConvert is 15 kb and NConvert is 409 kb. This fact is the most significant disadvantage

I tried adding -q 70, the weight decreased to 406 kb, but it's still very much
cday
XnThusiast
Posts: 2942
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Using different input and output directories

Post by cday »

agdabn wrote: Wed Mar 03, 2021 9:32 am Yes, that's right.
The image size is not 500x500
And the weight of XnConvert is 15 kb and NConvert is 409 kb. This fact is the most significant disadvantage

I tried adding -q 70, the weight decreased to 406 kb, but it's still very much
The immediate problem is that the NConvert pixel dimensions are not as expected, I have posted a request about that: Resize -- Fit option supported?.

3000 = 6 x 500, so 3000x3000px has 36 times as many pixels as 500x500px, so a much larger file size.

Also, a detail, the JPEG sub-sampling is 1x1,1x1,1x1 rather than 2x2,1x1,1x1, which may improve quality slightly, but may also increase the file size, or maybe only increase processing time, I'm not sure.

You could try experimenting with different settings while waiting for a possible answer from Pierre the developer on whether the 'Fit' option is currently supported in NConvert, it may possibly not be, and if so the correct code to use.
agdabn
Posts: 10
Joined: Tue Mar 02, 2021 9:30 am

Re: Using different input and output directories

Post by agdabn »

Oh, cday, thank you so much for your help.

We will wait for the developers ' response
cday
XnThusiast
Posts: 2942
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Using different input and output directories

Post by cday »

agdabn wrote: Wed Mar 03, 2021 10:32 am Oh, cday, thank you so much for your help.

We will wait for the developers ' response
I hope we don't have to wait too long, Pierre is the only developer of all xnview software and inevitably has limited time... :wink:
cday
XnThusiast
Posts: 2942
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Using different input and output directories

Post by cday »

I have done some tests and determined that the -resize option, which seemed to be the likely cause of your problem, operates correctly.

But testing using the following NConvert code used in your For loop:

Code: Select all

NConvert_x64_7.70\nconvert -ratio -rtype lanczos -rflag decr -rflag orient -resize 500 500 -sharpen 50 -dpi 96 -clean 95 Original.jpg

...the code runs as expected producing a 500x500px image until the -clean 95 option is added, it then doesn't run.

Looking at the NConvert help file, -clean 95 is not valid code, the 95 is not a valid value.

But the JPEG 3000x3000px output you reported has not been reproduced, unexplained, so you should probably examine your code and retest.
Post Reply