Image Thumbnail Generating Script

- - posted in Linux | Comments

I have often wished that I could easily convert several images to a smaller size simultaneously. This is useful for batch resizing images for thumbnails, galleries, or use on the web.

On a linux system with imageMagick installed, you can use the script at the end of this post to batch convert the images.

I use it to create thumbnails and scaled images for my online photo gallery using the following commands. ./imagethumbnail.sh “*.jpg” “800x600” “web/”

./imagethumbnail.sh “*.jpg” “150x112” “web/thb

This creates a reasonable sized “large” image at 800x600 and a thumbnail at 150x112. Makes managing new images in my gallery much easier. Hopefully you’ll find it useful too.

Contents of imagethumbnail.sh

#!/bin/bash
SEARCH=$1
SIZE=$2
DEST=$3

if [ $# -lt 3 ]
then
echo "You must pass three arguments 1) The search string (usually *.jpg) 2) The destination size I.E. 500x374 3) The destination directory"
exit 1
fi

for i in $SEARCH
do
echo "Converting $i"
convert -resize $SIZE $i -resize $SIZE +profile '*' $DEST$i
done

Comments