Blog
019434th since April 04, 2007
R
Jul 19, 2008 ( Saturday )
( 171 )
bash to automate generating thumbnails
Generating a thumbnail from the original image is not hard, just read the command-line options for Linux convert command (frontend for ImageMagick). While batch handling over 1M images files at one shot need some scripts. This is where bash kicks in and make your life easier. Below is a short bash script I wrote last night which worked perfectly for my work:

#!/bin/bash
# Usage : ./mkthumb.sh

imagedir=/data/pictures
thumbdir=/data/thumbnails

find "$imagedir" -type f -print | while IFS='\n' read -r image; do
    thumb=${image/$imagedir/$thumbdir}
    thumbfiledir=${thumb%/*}
    if ! [ -d "$thumbfiledir" ]; then
        mkdir -p "$thumbfiledir"
    fi
    echo " |-- $(( i++ )) converting '$image' to '$thumb'"
    convert "$image" -thumbnail 120 "$thumb"
done


and then run it as follows:

bash~ ./mkthumb.sh >20080718.thumbnail.log 2>20080718.thumbnail.err &
bash~ tail -f 20080718.thumbnail.log
Add tags: automation bash

by xicheng
10:41:53 | Read article | Ask xicheng
Modify an entry

Read the Guidance for the first time users or sign up for a new account

Need browser cookie to submit properly

Username: xicheng
Password:
Subject: