Jpegtran - Drag and drop batch file for multiple files

426 Views Asked by At

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

There are 1 best solutions below

3
On

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.