Sun Oct 4 23:03:21 EEST 2009

Recursively resize images within a directory with ImageMagick's convert

I needed to resize a whole directory containing pictures in 2048x1536 resolution
to a lower resolution to make a bunch of photos suitable for uploading to orthphoto . Orthphoto is a nice Orthodox website containing pictures relating to Orthodox Christian faith, you can see there many
categories in which are included a lot of churches sorted by countries, monks, holy relics, landscapes, everything
you can visual you can imagine somehow related to Orthodox Christainity.
To achieve that I used convert which is a part
of ImageMagick ,
(a collection of nice console programs to edit, convert and compose images).
Here is the code I ussued to convert all the images contained in a certain irectory from their
default image size resolution (2048x1536) to (640x480) pixels.
The program I used to convert the images is called convert
Here is how:

cd /some/dir;
quality="64";
for i in *; do
name=$(echo $i|sed -e "s#\.# #g"|awk '{ print $1 }');
convert -resize 640x480 -quality $quality $i ${name}_res.jpg; done;

The above code would resize all the images in /some/dir to a resolution 640x480.
Further it could easily be scripted to make it execute via php or any other web oriented
language.
It's an interesting fact that using Gimp to convert the image would resize images compressing
the output images a way better. Gimp usually saves you something like +30kb or even more,
while the quality is better than convert's.
However I have to investigate further how to script the same thing via Gimp.