tn() { local verbose=0 local raw=0 if [ "$1" = "-v" ]; then verbose=1 shift elif [ "$1" = "-w" ]; then raw=1 shift fi if [ ! -f $1 ]; then echo "invalid filename: $1" return 1 fi local filename=$1; shift local basename=`basename $filename|sed -e 's,^\(.*\)\.\(.*\)$,\1,'` local filetype=`basename $filename|sed -e 's,^\(.*\)\.\(.*\)$,\2,'` local newfile="$basename.tn.$filetype" local tmpfile="/tmp/.tn.$USER.$$" local alt=$1; shift local pos=$1; shift local args="-filter Cubic -verbose -sample 100x100" case $filetype in gif) args="-negate -transparency black colors 16 $args -compress None";; jpg) args="$args -compress JPEG" esac convert $args $filename $newfile &> $tmpfile if [ $? != 0 ]; then echo "conversion failed." cat $tmpfile return 1 fi local tout=`grep ".tn" $tmpfile` local geo=`echo $tout | cut -d" " -f2` local igeo=`echo $geo | cut -d"=" -f1` local tgeo=`echo $geo | cut -d">" -f2` local iwidth=`echo $igeo | cut -d"x" -f1` local iheight=`echo $igeo | cut -d"x" -f2` local twidth=`echo $tgeo | cut -d"x" -f1` local theight=`echo $tgeo | cut -d"x" -f2` local isize=`grep -v ".tn" $tmpfile | cut -d" " -f4` local tsize="" local tcolors="" case $filetype in gif) tsize=`echo $tout | cut -d" " -f5` tcolors=`echo $tout | cut -d" " -f4 | cut -dc -f1`;; jpg) tsize=`echo $tout | cut -d" " -f4` tcolors="16m";; esac rm -f $tmpfile if [ "$alt" = "left" -o "$alt" = "right" -o "$alt" = "center" ]; then pos=$alt alt="" fi if [ "x$alt" = "x" ]; then alt="$filename ($igeo, $isize)" fi if [ $verbose != 0 ]; then echo "" echo "read image $basename ($filetype, $igeo, $isize)." echo "wrote thumbnail $newfile ($tgeo, $tsize)." echo "" echo "" echo "asp image tag:" echo "" fi if [ $raw = 0 ]; then echo "<%" echo " Call showImage(\"$basename\", \"$filetype\", \"$filetype\", _" echo " $twidth, $theight, $iwidth, $iheight, _" echo " \"$alt\", \"$pos\")" echo "%>" else echo "$basename;$filetype;$filetype;$twidth;$theight;$iwidth;$iheight;$alt;$pos" fi }