Blog
053527th since April 04, 2007
R
1 - 1 of totally 1 entry in Jul, 2008 found
Jul 19, 2008 ( Saturday )
( 284 )
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 | Add a comment | Modify entry | Ask xicheng