0

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?

mc0e
  • 2,699
  • 28
  • 25
Bálinth István
  • 93
  • 1
  • 1
  • 4
  • Interesting but I think it's unlikely in batch. – Jonas Sep 16 '16 at 08:06
  • 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)](http://ss64.com/nt/syntax-args.html)... – aschipfl Sep 16 '16 at 08:22

1 Answers1

1

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.

Community
  • 1
  • 1
Jonas
  • 1,105
  • 1
  • 15
  • 21