How to batch convert JPEG images with jpegtran on Windows

0

Is it possible to batch convert a folder of JPEG images using jpegtran on Windows?
I normally use the following command for one file, but I'm not sure how to apply it to an entire directory of JPEG files:

jpegtran -copy none -optimize a.jpg b.jpg

Thank you.

HartleySan

Posted 2015-08-12T12:36:22.017

Reputation: 125

Answers

4

How do I operate jpegtran on a bunch of images at once?

I've not used jpegtran myself before, but based on your example command you can enter the following at a command prompt:

cd /path/to/where/images/are/stored
for %f in (*.jpg) do jpegtran -copy none -optimize %f %~nf-new.jpg

Note that this assumes you are running from cmd.exe command prompt; if you are in a batch file the %s need doubled to %%.

See the for reference for more information.

Explanation

for %f in (*.jpg) - loop through all files ending in .jpg extension using the variable %f

do jpegtran -copy none -optimize - do this action (using your example jpegtran above)

%f - variable with filename plus extension (original file)

%~nf - variable with filename without extension as per reference above (new file with -new.jpg appended)

bertieb

Posted 2015-08-12T12:36:22.017

Reputation: 6 181

I never knew about that for command from the Windows command line. Very awesome. It should be noted that jpegtran.exe either needs to be in the images folder you're running the command from, or it has to be registered as part of the PATH environment variable. Also, neither of your links worked, but I found information about for here.

– HartleySan – 2015-08-13T01:44:21.067