#!/bin/bash -norc
# Create thumb-nail jpeg images for all jpeg files in a directory.
# Also a .html template file is created with the references, proper
# thumb-nail pixel sizes and original file size for each image.
# Find the path to the current directory (no trailing /)
CURPATH=`pwd`
# Pick out the fragment of the path that is needed in a URL. We assume here
# that the directory is somewhere in the G0 ftp area specified either
# in absolute terms or using a link (ftp) from the codagz home directory.
HTMLPATH=`echo $CURPATH | sed "s#/home/codagz/ftp/##g"`
HTMLPATH=`echo $HTMLPATH | sed "s#/pub/ftp/pub/G0/##g"`
# Make sure that the "thumbs" directory exists.
mkdir thumbs
# Create a blank html file
rm README.html
# Add a header to the html file.
cat <<-endhtml >README.html
-title-
-title-
endhtml
# For each jpeg file, generate a thumb-nail and add a line
# to the html file.
for FILE in `ls *.jpg`; do
echo 'Processing ' $FILE
# Generate a name for the intermediate file
PNMNAME=/tmp/`basename $FILE .pnm`
# Convert the input file to a thumb-nail file pnm format
# file that fits in a 100X100 pixel box.
djpeg -pnm $FILE | pnmscale -xysize 100 100 > $PNMNAME
# Find the width and height of the resulting file.
STATS=(`pnmfile $PNMNAME`)
# Now convert the pnm thumb-nail file to a jpeg file
# in the thumbs sub-directory and get rid of the intermediate
# file.
cjpeg -optimize $PNMNAME >./thumbs/thumb_$FILE
rm $PNMNAME
# Get the file size in kbytes (0'th element of this array)
DISKSIZE=(`du -k $FILE`)
# Add an entry to the html file for this picture.
cat <<-endhtml >>README.html
|
|

${DISKSIZE[0]} kb
|
endhtml
done
# Add the trailer to the file.
cat <<-endhtml >>README.html
endhtml