#!/bin/sh
#
# html4images1 - in a directory with images, generate a HTML page with previews
#
# $Id$
# see ./html4images2 for a fancier version
thumbheight=64x48 # thumbnail size in pixels
ext=png
IsImage() { file "$1" | fgrep ' image ' >/dev/null; }
# is this file an image?
IsThumb() { case "$1" in thumb-*.$ext|*/thumb-*.$ext) return 0;; *) return 1;; esac; }
# is this image a thumbnail?
ThumbOf() { echo `dirname $1`/thumb-`basename $1` | sed 's/\.[^.]*$/.'$ext'/'; }
# name of thumbnail corresponding to given image
PreviewOf() { if [ "$thumbs" -gt 0 ]; then ThumbOf "$1"; else echo "$1"; fi; }
Index() { if [ "$thumbs" -gt 0 ]; then echo thumbs.html; else echo all.html; fi; }
me=`basename "$0"`
Warn() { echo "$me: warning: $@" 1>&2; }
MakePreview()
(
cd $d || return # TODO: improve error handling
good_fs=
for f in `find * -type f`
do
if IsThumb $f
then
Warn skipping $f, a thumbnail
continue
elif [ ! -f "$f" ]
then
Warn skipping $f, not a file
continue
elif IsImage "$f"
then
if [ "$thumbs" -gt 0 ]
then
convert $f -geometry $thumbheight `ThumbOf $f` &&
good_fs="$good_fs $f"
else
# trust the image as it is
good_fs="$good_fs $f"
fi
else
Warn skipping $f, not an image
continue
fi
done
index=`Index`
if [ -z "$good_fs" ]
then
continue
elif [ \( $force = 1 \) -o \( -f $index \) ]
then
Warn not generating $d/$index, it already exists
continue
fi
cat > $index <
image index for $d
Images in/under directory $d
ZZ
for f in $good_fs
do
cat >> $index <
ZZ
done
cat >> $index << ZZ