Page 1 of 1

Batch script to create multiple sizes of one image

Posted: 2012-04-17T09:39:28-07:00
by TwoXfour
Hi guys, I've had a good look at some examples and the references, but its a bit of a steep learning curve, and I was hoping for a bit of help with a .bat for Windows.

I'd like to resize an image in a folder to multiple sizes if possible.
Assume I have a couple of .png images over 2000px square in a folder, I'd like to execute the .bat and have it create a folder per source image containing: 1024x1024, 512x512, 256x256, 128x128, 64x64, 32x32 re-sized versions of source image.

If someone could point me to a example I could modify, or idiotproof references, I'd be very grateful, Thankyou :)

Re: Batch script to create multiple sizes of one image

Posted: 2012-04-17T09:53:46-07:00
by fmw42
You have to do it one image at a time

convert image.jpg \
\( -clone 0 -resize 1024x1024 -write image_1024.jpg \) \
...
\( -clone 0 -resize 32x32 -write image_32.jpg \) \
null:

see parenthesis processing and clones at
http://www.imagemagick.org/Usage/basics/#parenthesis

On windows do not escape the parens with \ and replace the end of line \ with ^

see syntax differences at
http://www.imagemagick.org/Usage/windows/

Re: Batch script to create multiple sizes of one image

Posted: 2012-04-17T10:22:34-07:00
by TwoXfour
Excellent, got it working, thank you for your help :)

Re: Batch script to create multiple sizes of one image

Posted: 2012-04-17T14:55:28-07:00
by TwoXfour
I have encountered a slight hiccup though... :D
When run from cmd, it works as expected, but executed as a .bat from explorer, it give me... Invalid Parameter - -set

Any ideas?

Code: Select all

@ECHO OFF
::Batch resize image to common sizes

convert In\* ^
 -set filename:fname "%%f" ^
 ( -clone 0 -resize 1024x1024 -write Out\1024_%%[filename:fname] ) ^
 ( -clone 0 -resize 512x512 -write Out\512_%%[filename:fname] ) ^
 ( -clone 0 -resize 256x256 -write Out\256_%%[filename:fname] ) ^
 ( -clone 0 -resize 128x128 -write Out\128_%%[filename:fname] ) ^
 ( -clone 0 -resize 64x64 -write Out\64_%%[filename:fname] ) ^
 ( -clone 0 -resize 32x32 -write Out\32_%%[filename:fname] ) ^
null:

Re: Batch script to create multiple sizes of one image

Posted: 2012-04-17T15:18:11-07:00
by fmw42
I am not a windows user, but many scripting environments need you to provide the full path to convert.

Re: Batch script to create multiple sizes of one image

Posted: 2012-04-17T16:51:50-07:00
by anthony
"convert" in windows just happens to also be a silly utility that microsoft provided.

Commonly people rename "convert" to "im_convert" to avoid this.

IMv7 (in alpha development) will have a new command called "magick" that will replace "convert".
So I recommend you rename your "convert" command to "magick" instead, until IMv7 becomes
generally available.

This 'name change' ensures it to does not clash with existing utilities. The new command will also have a LOT of new features that are not available or have slight in-compatabilities with the older "convert" command.

Re: Batch script to create multiple sizes of one image

Posted: 2012-04-17T17:04:39-07:00
by TwoXfour
Cheers Anthony, that's the one!
Thanks for everyone's input.