# File: /u/kscott/public_html/software/other/make_thumbs/make_thumbs # Author: K. Scott Rowe # Time-stamp: <03/15/2008 19:33:05 kscott@rainbow> #!/bin/sh # # File: /dolomite/home/kscott/bin/make_thumbs # Author: K. Scott Rowe # Time-stamp: <03/15/2008 19:32:40 kscott@rainbow> #improvements # - more filetypes supported (TIFF, PNG, ...) # - have a comment file to associate text with images and pull out that # text to be put in thumb.html. Also have title and leading text # available for the top of the page # - check for pre-existing thumb images, and dont recreate them # - solaris is stupid and doesn't come with rev, need a work-around USAGE="Usage: $0 -[HVhv] [, ...]" VERSION="$Id: make_thumbs,v 1.4 2004/08/31 03:35:55 kscott Exp $" VERBOSE= HTML= count=0 Die() { echo "$*" exit 1 } Usage() { echo $USAGE echo "" echo " -H Write out thumb.html file as well a make thumbnails." echo "" echo " -V Print version information and quit." echo "" echo " -h Print this help file and quit." echo "" echo " -v Run in verbose mode." echo "" exit 0 } HtmlHead() { echo "" echo "" echo "" echo '" echo "" echo "" echo "" echo "" echo '' echo '' } HtmlFoot() { echo "
" echo "" echo "

" echo "


" echo 'Created by make_thumbs:
' echo "" echo "" } DoGif() { if [ $VERBOSE ] ; then echo "INPUT FILE: \"${FILE}.${EXTENSION}\"" (giftopnm -verbose "${FILE}.${EXTENSION}" | pnmscale -xysize 100 100 | ppmquant 256 | ppmtogif > "${FILE}_thumb.gif") || (echo "OOPS: cleaning up" ; rm "${FILE}_thumb.gif") echo "OUTPUT FILE: \"${FILE}_thumb.gif\"" else (giftopnm "${FILE}.${EXTENSION}" | pnmscale -xysize 100 100 | ppmquant 256 | ppmtogif > "${FILE}_thumb.gif") > /dev/null 2>&1 || (echo "OOPS: cleaning up, use -v for more info" ; rm "${FILE}_thumb.gif") fi if [ "${count}" = "4" ] ; then # how many pics in a row count=0 fi if [ $HTML ] ; then FILESIZE=`ls -ks ${FILE}.${EXTENSION} | awk '{print $1}'` >> thumb.html if [ "${count}" = "0" ] ; then echo "" >> thumb.html fi echo " " >> thumb.html echo "
" >> thumb.html echo " ${FILE}.${EXTENSION}
" >> thumb.html echo " ${FILESIZE}K" >> thumb.html fi count=`expr ${count} + 1` } DoJpeg() { if [ $VERBOSE ] ; then echo "INPUT FILE: ${FILE}.${EXTENSION}" (djpeg -verbose -colors 256 -fast "${FILE}.${EXTENSION}" | pnmscale -xysize 100 100 | ppmquant 256 | cjpeg -verbose > "${FILE}_thumb.jpg") || (echo "OOPS: cleaning up" ; rm "${FILE}_thumb.jpg") echo "OUTPUT FILE: \"${FILE}_thumb.jpg\"" else (djpeg -colors 256 -fast "${FILE}.${EXTENSION}" | pnmscale -xysize 100 100 | ppmquant 256 | cjpeg > "${FILE}_thumb.jpg") > /dev/null 2>&1 || (echo "OOPS: cleaning up, use -v for more info" ; rm "${FILE}_thumb.jpg") fi if [ "${count}" = "4" ] ; then # how many pics in a row count=0 fi if [ $HTML ] ; then FILESIZE=`ls -ks "${FILE}.${EXTENSION}" | awk '{print $1}'` >> thumb.html if [ "${count}" = "0" ] ; then echo "" >> thumb.html fi echo " " >> thumb.html echo "
" >> thumb.html echo " ${FILE}.${EXTENSION}
" >> thumb.html echo " ${FILESIZE}K" >> thumb.html fi count=`expr ${count} + 1` } if [ "$1" = "" ] ; then echo "$USAGE" exit 1 fi if [ ! -f "$1" ] ; then while [ ! -f "$1" ] ; do case "$1" in -H) HTML=1 ;; -V) echo $VERSION exit 0 ;; -h) Usage ;; -v) VERBOSE=1 ;; *) echo $USAGE exit 1 ;; esac shift done fi if [ $HTML ] ; then HtmlHead > thumb.html fi while [ "$1" ] ; do echo "${1}" | grep "_thumb\." > /dev/null && isthumb=1 || unset isthumb while [ "$1" -a "$isthumb" ] ; do # if [ $VERBOSE ] ; then echo "skipping $1" # fi shift done FILE_TYPE="`file -b \"$1\" | awk '{print $1}'`" # learned this trick from icon. FILE="`echo $1 | rev | cut -d'.' -f2- | rev`" EXTENSION="`echo $1 | rev | cut -d'.' -f1 | rev`" if [ ! -f "${FILE}.${EXTENSION}" ] ; then # sanity check echo "Barbra Streisand" exit 1 fi case $FILE_TYPE in GIF) DoGif ;; JPEG) DoJpeg ;; *) echo "Error: unrecognized filetype ($FILE_TYPE)" esac shift done if [ $HTML ] ; then HtmlFoot >> thumb.html fi