#!/bin/sh

height=120

mkdir -p .thumbs

echo '<html><head><title>thumbnails</title></head>' >thumbs.html
echo '<body bgcolor="#a0a0a0"><font color="#ffffff"><table border="1">' >>thumbs.html

for i in *; do
    ftype=`file -i -b "$i" | grep image`

    if [ -n "$ftype" ]; then
        cur_h=`identify -format %h "$i"`

        if [ $? = 0 ]; then
            if [ "$cur_h" -gt "$height" ]; then
                convert "$i" -resize "x$height" ".thumbs/$i.jpg"
            else
                convert "$i" ".thumbs/$i.jpg"
            fi

            if [ $? = 0 ]; then
                echo '<tr>' >>thumbs.html
                echo "  <td><a href=\"$i\"><img src=\".thumbs/$i.jpg\"></a></td>" >>thumbs.html
                echo "  <td>$i</td>" >>thumbs.html
                echo '</tr>' >>thumbs.html
            fi
        fi
    fi
done

echo '</table></font></body></html>' >>thumbs.html