053527th since April 04, 2007
Xicheng's web log
----- a place to make mistakes and learn from scratch
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:
and then run it as follows:
#!/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
# 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
bash~ tail -f 20080718.thumbnail.log
[ Previous Page ] | [ Blog Main ]
Monthly archives
Site Statistics
Newest comments
My links
Add new links
Advanced Search
Blog
