Resizing multiple images

I’m sure there are easier ways, and better I assume, to reduce the size of multiple images at once. But there was some point in time where I couldn’t resist the urge of solving this myself using ImageMagick and Tcl/Tk. ImageMagick – for me – is just a bunch of nifty command line image processing tools. It allows you to not only modify existing images, but also create new ones, and do all sorts of awesome image processing.

ImageMagick runs on practically every operating system you can think of. I used Macports to install it on my Mac. To make your Mac more Unix-like, you’d have to install Xquartz, which just might be useful for Tcl/Tk later on.

With ImageMagick you could, for example, create a colorful image fairly easy with the following command:

convert -size 1600x1200 gradient: \
        -separate -virtual-pixel tile \
        -spread 10000 -combine -blur 0x5 \
        -normalize -quality 50 test-input.jpg

Which would result in something like:


…Which could be useful if you need an image for testing other ImageMagick-commands.

Now suppose I have a whole stack of (test) images that are actually to large and need to be resized to 640×480 or so. The convert command can be used for this as well:

convert -resize 640x480 test-input.jpg test-output.jpg

This resizes the test-input.jpg file to 640×480 as test-output.jpg. You could use the convert command in a batch-file on Windows as shown here below:

@echo off


if "%~f1"=="" goto continue
set new=%~d1%~p1%~n1_new.jpg
set new_x_small=%~d1%~p1%~n1_web_extra_small.jpg
set new_small=%~d1%~p1%~n1_web_small.jpg
set new_medium=%~d1%~p1%~n1_web_medium.jpg
set new_large=%~d1%~p1%~n1_web_large.jpg

echo Now converting %~nx1 for online usage...
echo      *** This may take a while! ***
echo This screen will close itself. Please wait.

cd "c:\program files\im"
convert.exe -strip "%~f1" "%new%"
convert.exe -resize 150x -despeckle -quality 70 "%new%" "%new_x_small%"
convert.exe -resize 200x -despeckle -quality 75 "%new%" "%new_small%"
convert.exe -resize 500x -despeckle -quality 80 "%new%" "%new_medium%"
convert.exe -resize 1000x -despeckle -quality 85 "%new%" "%new_large%"

del /f /q "%new%"


goto loop


echo Done

This batch-file assumes that ImageMagick is installed in “c:\program files\im”. I’ve added the ‘despeckle’ option to improve the overall image quality a bit and increased the compression factor with the ‘quality’ option to the convert command.

This is all nice, but to an average user, it’s to cumbersome. So quite some time ago, in 2006 (judging by the CVS timestamp ;-)), I wrote a user interface in Tcl/Tk to get a little more user friendliness around resizing and ImageMagick on my Linux-box, which – of course – can be used just as well on a Mac! It looks something like this  (depending on OS):


That little bit of Tcl/Tk-code can be found here. Download the file, place it on your desktop and check if it can be executed or modify its permissions (chmod +x <filename> from the if you’re using Mac OS X). For Mac and *nix users, the file is not required to have an extension. Make sure the convert command can be found from the command line. This is usually done by adding its path to the PATH-variable, which is documented in the manual-page of bash.

You should be able to start it by double clicking on the icon on your desktop. Then specify the directory containing the images that need to be processed, and the directory that will contain the processed images. These are preferably two different directories, so you can easily copy the resulting files later. Otherwise you’d have to select the new images from existing images, which can be quite a hassle. You can either pick a predefined size, or scale the image in precent of the original. As a feature, I’ve added an option to generate a HTML gallery webpage.


The command line is immensely powerful when it comes to automating repetitive tasks. And although it feels somewhat strange as visual feedback is completely lacking when images are being processed, it works pretty well!

Now as always, there is at least one missing feature, and in this case it’s automatic rotation of photo’s, which I’ve written about earlier. Combining these two and produce something that would really useful? Yes, someday when I have more time…









This entry was posted in Image processing, Shell script and tagged , , , , , , , . Bookmark the permalink.