#!/bin/sh # Image Directory Viewer by Dave Taylor for LinuxJournal # More scripting goodness at http://www.intuitive.com/wicked/ # or contact me directly at taylor at intuitive dot com # Drop this in an image directory, name it "index.cgi" and # go into your httpd.conf file to ensure that you can run CGI # scripts in that folder. Then enjoy! :-) maxsize=150 # max thumbnail size, in pixels maxperline=3 # max images per table row imgcount=0 # keep track of images displayed totcount=0 # and total number of entries listed linecount=0 # images displayed on current line figuresize() { width="$(identify $1|cut -d\ -f3|cut -dx -f1)" height="$(identify $1|cut -d\ -f3|cut -dx -f2)" } echo "Content-type: text/html" echo "" echo "" echo "Image Directory Utility by Dave Taylor" echo "" echo "
Displaying directory $(pwd)

" echo "" for name in * do if [ ! -z "$(file -b $name|grep 'image data')" ] then figuresize $name if [ "$height" -gt $maxsize -o "$width" -gt $maxsize ] ; then if [ $height -gt $width ] ; then # we'll want to constrain height factor="$(echo "scale=4;$maxsize/$height"|bc)" newheight=$maxsize newwidth="$(echo "$factor*$width"|bc|cut -d. -f1)" else factor="$(echo "scale=4;$maxsize/$width"|bc)" newwidth=$maxsize newheight="$(echo "$factor*$height"|bc|cut -d. -f1)" fi # echo "Given $width x $height, scaled to $newwidth x $newheight" width=$newwidth height=$newheight fi if [ $linecount -eq $maxperline ] ; then # new row of table echo "" linecount=0 fi echo "" linecount=$(( $linecount + 1 )) imgcount=$(( $imgcount + 1 )) else # not an image file, don't display anything # echo "$name" fi totcount=$(( $totcount + 1 )) done echo "
" echo "$name
" echo "$name

($height x $width)
" # close up the table neatly echo "

Displayed $imgcount images out " echo "of $totcount entries total." echo "
" exit 0