On Tue, Aug 26, 2003 at 09:41:06AM -0500, Shawn wrote:
> I want to take an ls of a directory and dump it into an html file (pics) for temporary use. Until I get a sight up with thumbnails (read lack of time right now).
> What's the best way to do this?

This script will make resized jpgs/thumbnails/html-index out of a dir full
of jpgs, suitable for web viewing.  Uses convert from ImageMagick.

#!/bin/sh -v
SCRIPTNAME=$0
if [ "$1" == "" ] || [ "$1" == "--help" ] || [ "$1" == "-?" ] ; then
echo use# $SCRIPTNAME directory
echo where directory = path to scan for .jpg files.
exit 1
fi

if ! [ -d $1 ]; then
echo Error: The first parameter should be a directory name with picts.
exit 1
fi

WEBDIR=$1_web
THUMBDIR=thumbdir
THUMBFILE=$WEBDIR/thumb.html
#BAKDIR=`date +m%md%d`

if [ "$3" != "_2NDPASS_" ] ; then
# first invocation, where we create a new backup path based on

# create our thumbnail directory.
echo Creating thumbnail directory
mkdir -p $WEBDIR/$THUMBDIR

echo "<html><head><title>Picts " `date` > $THUMBFILE
echo "</title></head>" >> $THUMBFILE
echo "<H1><B>Pictures</B></H1><P>" >> $THUMBFILE
#find $1 -name *.jpg -exec echo \<IMG SRC=\""{}"\"\>  >> $THUMBFILE \;

# use find to recursively call ourself as 2nd invocation to
# convert the file.
find $1 -name "*.jpg" -exec ./$SCRIPTNAME $1 "{}" _2NDPASS_ \;

echo "</body></html>" >> $THUMBFILE
exit 0
fi

# 2nd invocation(find calls us on 2nd invocation.  We are given
# $3 = "_2NDPASS_"

if ! [ "$3" == "_2NDPASS_" ]; then
echo Parameter 3[$3] not a 2nd phase operation.
exit 1
fi

if ! [ -d "$1" ]; then
echo The folder [$1] does not exist.
exit 1
fi

if ! [ -f "$2" ]; then
echo The file [$2] does not exist.
exit 1
fi

FNAME=`basename "$2"`
DNAME=`dirname "$2"`
echo \<A HREF=\"$FNAME\"\>\<IMG SRC=\"$THUMBDIR/$FNAME\" ALT=\"$FNAME\" \> \</A\>  >> $THUMBFILE
#echo "<BR>" >> $THUMBFILE
convert -quality 35 -geometry 320x256! $2 "$WEBDIR/$THUMBDIR/$FNAME"
convert -quality 50 $2 "$WEBDIR/$FNAME"



_______________________________________________
TCLUG Mailing List - Minneapolis/St. Paul, Minnesota
http://www.mn-linux.org tclug-list at mn-linux.org
https://mailman.real-time.com/mailman/listinfo/tclug-list