Batch script to create multiple sizes of one image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
TwoXfour
Posts: 4
Joined: 2012-04-17T09:19:56-07:00
Authentication code: 13
Location: Oxford, UK

Batch script to create multiple sizes of one image

Post 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 :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Batch script to create multiple sizes of one image

Post 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/
TwoXfour
Posts: 4
Joined: 2012-04-17T09:19:56-07:00
Authentication code: 13
Location: Oxford, UK

Re: Batch script to create multiple sizes of one image

Post by TwoXfour »

Excellent, got it working, thank you for your help :)
TwoXfour
Posts: 4
Joined: 2012-04-17T09:19:56-07:00
Authentication code: 13
Location: Oxford, UK

Re: Batch script to create multiple sizes of one image

Post 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:
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Batch script to create multiple sizes of one image

Post by fmw42 »

I am not a windows user, but many scripting environments need you to provide the full path to convert.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Batch script to create multiple sizes of one image

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
TwoXfour
Posts: 4
Joined: 2012-04-17T09:19:56-07:00
Authentication code: 13
Location: Oxford, UK

Re: Batch script to create multiple sizes of one image

Post by TwoXfour »

Cheers Anthony, that's the one!
Thanks for everyone's input.
Post Reply