Home
|
UNIX
|
Practical
KSH / ImageMagick powered Photo gallery
Use the source, Luke :
#!/bin/ksh
set -e
fclean() {
[[ -d thumbs ]] && rm -rf thumbs
[[ -d small ]] && rm -rf small
[[ -f $dest ]] && rm -f $dest
[[ -f $dest.tmp ]] && rm -f $dest.tmp
true
}
fphotolibrary() {
[[ -d thumbs ]] || mkdir thumbs
[[ -d small ]] || mkdir small
for f in `ls -1 | egrep '\.jpg$|\.JPG$'`; do
[[ ! -f small/s$f ]] && convert -resize 600x600 $f small/s$f
[[ ! -f thumbs/t$f ]] && convert -resize 100x100 $f thumbs/t$f
cat >> $dest.tmp <<-EOF9
<a href="small/s$f"><img style="border:0;" src="thumbs/t$f" /></a>
EOF9
done
}
[[ ! `which convert` ]] && echo "ImageMagick missing" && exit 1
[ ! $1 ] && echo "1st argument missing" && exit 1
dest=index.html
cd $1
[[ $2 == clean ]] && fclean
[[ -f $dest.tmp ]] && rm -f $dest.tmp
fphotolibrary
mv -f $dest.tmp $dest
cd ..