#!/bin/sh
#
# simple JPG thumbnail & index file generator
# Written by David Santinoli <david at santinoli.com>
# Dependencies: djpeg, cjpeg, pnmscale
#
# No command line parameters. Everything is hardwired, which is by far the best
# programming style :-]
#
# Run this script in the directory containing the JPEGs. Both a `thumb'
# directory and an `index.html' file (truncating any previous one) are created.
#

COLS=4
HEIGHT=80
mkdir -p thumb
echo "<body bgcolor=white>" > index.html
echo -e "<table cellpadding=10 border=1 width=100%>\n<tr>" >> index.html
count=0
# for i in *.jpg *.JPG ; do
for i in `ls -rt *.jpg *.JPG` ; do
   if [ -f $i ] ; then
      echo Now scaling $i
      djpeg $i | pnmscale -ysize $HEIGHT | cjpeg > thumb/$i
      echo -e "<td align=center>\n  <a href=$i><img src=thumb/$i vspace=5></a><br>$i\n</td>" >> index.html
      count=$(($count+1))
      if [ $count -eq $COLS ] ; then
         echo "</tr><tr>" >> index.html
         count=0
         fi
      fi
done

while [ $count -ne $COLS ] ; do
   echo "<td>&nbsp;</td>" >> index.html
   count=$(($count+1))
done
   
echo -e "</tr></table>\n<br><br>\n" >> index.html
echo "<i>index compiled with <a href=http://santinoli.com/software/minio>minio</a></i>" >> index.html
echo "</body>" >> index.html
