0
votes

Is it possible to create a batch file capable of optimizing multiple images at once? Drag and drop multiple .jpg files on it? (and have the output be something like image1.jpg, image2.jpg, image3.jpg in a separated folder named "Optimized"?

If jpegtran is not the perfect tool for doing this, then I am open for any other suggestion. Maybe imagemagick is a better tool for this?

1
Interesting but I think it's unlikely in batch. - Jonas
Files dragged-and-dropped onto a batch file appear as its arguments, which can be accessed by %1, %2, %3, or all at once, %*; type call /? into a command prompt window and read the help, and also reference this resource: Command Line arguments (Parameters)... - aschipfl

1 Answers

1
votes

This code below allows you to drag and drop files onto it and then copies them to %userprofile%\Desktop\Optimized on your desktop.

@echo on
setlocal ENABLEDELAYEDEXPANSION
set "params=!cmdcmdline:~0,-1!"
set "params=!params:*" =!"
set count=0
for %%G IN (!params!) do (
  set /a count+=1
  set "item_!count!=%%~G"
  rem echo !count! %%~G
)
for /L %%n in (1,1,!count!) DO (
  xcopy "!item_%%n!" "%userprofile%\Desktop\Optimized"
)
pause
exit

Check out THIS LINK

I tested it on .jpeg and .png files apparently there is a limit of 2048 characters as well. see the link for more info.