My girlfriend would like to convert a number a photos (from my 6MP Canon camera) into a smaller size to send to some of her friends. I would like to apply some transformations to images (e.g. rotating, drawing a frame around it, etc.) automatically. It’s nice that usually we have the same thing in our minds, isn’t it?
Both ideas pointed to a command line tool that can accomplish this easily on plenty of images at once.
Well, I’m not really good at computer graphics and I don’t really know the tools available for this. To be honest I was not very keen on studying computer graphics in the university. So I had to look for a solution…
First I started with the one I found in the Applications menu of my Ubuntu: GIMP. I knew that it offers scripting capabilities (Script-Fu) and is extensible with plug-ins. When I searched for GIMP documentation somehow I found ImageMagick + jhead and fall in love.
So here’s what we can do.
Ensure that ImageMagick and jhead is installed:
$> apt-get install imagemagick $>apt-get install jhead
Using jhead First rotate all the images based on their Orientation field in EXIF and add a comment to them with one command:
$> jhead -cl 'Rethymno | Santorini, Greece, 3-5 Sep 2008' -autorot ./*
Then resize the image using the Lanczos filter:
$> convert img_1623.jpg -filter Lanczos -resize 800 img_1623s.jpg
To apply this on a series of images I wrote a small shell script:
#!/bin/bash
if [ -z $1 ] then echo "Usage: $0 width" exit -1 fi
SIZE=$1 IMGS=`find . -name '*.jpg' -print`
for img in $IMGS
do
new_img_name=`echo $img | sed s/\.jpg/_small\.jpg/`
echo -n "Resizing $img to $SIZE px -> $new_img_name "
convert $img -filter Lanczos -resize $SIZE $new_img_name
echo Done.
done
exit 0