#!/usr/local/gnu/bin/bash # # This script scans the given JPEG files (whose names # must end in .jpg), generates a thumbnail in PNG and a reduced # version in JPEG of each, and generates an HTML page with all the # thumbnails and links to the reduced version and the original. # # If there is a file with the same name as the JPEG file, but with # "-d.html" instead of ".jpg", it will copy its contents underneath # the thumbnail. # # The HTML page with thumbnails is written to stdout, so you probably # want to call the script with a redirect: # # thumbnails *.jpg >index.html # # This script relies on the PBM and JPEG tools to be installed. # # Author: Bert Bos # Date: 8 July 1999 # # Copyright © 1995-2000 World Wide Web Consortium, (Massachusetts # Institute of Technology, Institut National de Recherche en # Informatique et en Automatique, Keio University). All Rights # Reserved. # See http://www.w3.org/Consortium/Legal/copyright-software.html # Change the copyright messages: # - copyshort = plain text to be embedded in the generated PNG & JPEG files # - copylong = HTML text to be added at the end of the thumbnail page copyshort='Copyright © '`date +%Y`' Bert Bos ' copylong="Copyright © "`date +%Y`" Bert Bos
Photos may be used freely, if copyright is kept with photo." # Other parameters w1=100 # Width of thumbnail w2=150 # Width of DIV (>= w1) h1=100 # Height of thumbnail h2=195 # Height of DIV (> h1 + 2*border) border=4 # Width of image border smallwd=640 # Width of smaller version smallht=480 # Height of smaller version thdir=thumb # Name of thumbnail directory smdir=small # Name of smaller images directory # Create a temporary file to hold the text for the copyright TMP=/tmp/copyright-$$ echo "$copyshort" >$TMP trap "rm $TMP" 0 # Create the directories for the thumbnails and the reduced JPEGs mkdir $thdir mkdir $smdir # Write the header of the HTML file. # Note: 'float: left' causes a bug in Netscape 4 and Opera 3.5 & 3.6 # (all images are in a single row, instead of as many as needed). # You may want to comment it out until there are newer versions of # those browsers. wrapht=`expr $border + $h1 + $border` echo "Thumbnails" echo "" echo "" # Loop over all arguments for f; do echo -e "Processing $f, \c" >&2 typeset -i size=`ls -l $f | cut -c30-40` size=`expr $size / 1024` echo -e "(${size} Kb), \c" >&2 h=`basename $f .jpg` # Basename of original image g=$thdir/${h} # Basename of thumbnail j=${g}.png # Full name of thumbnail i=${h}-d.html # Full name of description smallbase=$smdir/${h} # Basename of 640x480 version smallname=$smallbase.jpg # Full name of 640x480 version echo -e "thumbnail, \c" >&2 if [[ ! -f $j || $f -nt $j ]]; then djpeg $f | pnmscale -xysize $w1 $h1 | pnmtopng -text $TMP >$j fi echo -e "small \c" >&2 if [[ ! -f $smallname || $f -nt $smallname ]]; then djpeg $f | pnmscale -xysize $smallwd $smallht | cjpeg |\ wrjpgcom -cfile $TMP >$smallname fi typeset -i smallsize=`ls -l $smallname | cut -c30-40` smallsize=`expr $smallsize / 1024` echo "(${smallsize} Kb)" >&2 fileinfo=`pngtopnm $j | pnmfile` thumbwd=`echo $fileinfo | cut -d, -f2 | cut -d' ' -f2` thumbht=`echo $fileinfo | cut -d, -f2 | cut -d' ' -f4` echo "
" echo "
" echo " " echo "
" echo " ${size} Kb -" if [ $smallsize -lt $size ]; then echo " ${smallsize} Kb -" else rm $smallname fi echo " " if [ -f "$i" ]; then cat $i else echo " $h" fi echo "
" done # Add copyright message at the end echo "
" echo "
" echo "$copylong" echo "
" echo "" echo ""