Batch-Scaling a directory of jpeg images using ImageMagick’s “convert” cli tool

Recently, I had to scale down a series of images in different resolutions down to a web-friendly 600xsomething size so I could upload them to Zope’s internal Medusa ftp server without having to wait hours or breaking the resulting picture page with humongous images. Here’s how I did it, assuming the pics reside in a directory called “picdir” in my home directory:

cd ~/picdir
mkdir web # create a temporary dir to hold the scaled down images
for f in *jpg *JPG ; do
 convert -geometry 600x "$f" web/"$f"
 #convert to 600px width at most, let convert figure out the rest
  echo $file
done

Of course, this only works for landscape format pics, portrait format pictures will end up slightly larger because of their greater vertical size.

Leave a Reply

Your email address will not be published. Required fields are marked *