2 min read

Creating thumbnail images with convert

A little while ago, I found I had a bunch of images that needed thumbnails that were 100×75. This isn’t hard to do - I used convert and a pair of bash for loops.

The core was a call to convert, which is part of ImageMagick.

convert -thumbnail 100x75 input.jpg thumbnail.jpg

All of my images happened to be 4:3 - if they hadn’t, I might have used 100x75! or rotated/resized them.

Next, all my files had numbers of the form file01..file09 file10 file11… etc. If you’re nuts, you try to figure out how to do this in a single for-loop with a condition for the first 9 elements that start with 0.

If you’re lazy like me, you use two loops, with a cursor-up in bash so you don’t have to type as much:

export INFILEPREFIX=file
export OUTFILEPREFIX=file
for i in {1..9}; do convert -thumbnail 100x75 ${INFILEPREFIX}0${i}.jpg ${OUTFILEPREFIX}0${i}t.jpg; done
for i in {10..25}; do convert -thumbnail 100x75 ${INFILEPREFIX}${i}.jpg ${OUTFILEPREFIX}${i}t.jpg; done

For the non-thumbnails, I resized as well, using -resize 800x600.