#!/bin/ksh # jpeg-thumb-dir # makes thumbnails (if needed) and creates html_files containing links to # orig. using thumb images. # (HTML is relative to path supplied) # $Id: jpeg-thumb-dir,v 1.8 2002/12/08 16:48:21 johan Exp $ #################### # (C) 2000-2002 Johan van Zanten # johan@giantfoo.org # http://www.giantfoo.org/~johan # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # The GPL can be found at http://www.fsf.org/copyleft/gpl.html # Unlimited License to use this shell script is granted to anyone who # wants it. #################### HOSTNAME=`uname -n` ME=`basename $0` OS=`uname` OFwV=${OS}-`uname -r` DATE=`date` PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin export PATH case $OS in SunOS) PATH=$PATH:/opt/sfw/bin ;; NetBSD) PATH=$PATH:/usr/pkg/bin ;; esac #tmpfile=/tmp/${ME}.$$ # Echo our args to standard error. function errecho { echo $* >&2 } # The infamous usage function. function usage { errecho "usage: $ME [ -h[elp] ] [ -f ] [ -n num_pic_per_page]" errecho "\t [ -t 'Title for HTML' Page ] [ -s int ]" errecho "\t [ -o output_html_filename_prefix ]" errecho "\t [ -F 'Footnote for HTML' ] [ -Q ] dir-to-thumbnail" errecho "\t '$ME -h' for help" exit 1 } ### ### Defaults and configuration options ### max_row_width=649 pics_per_page=8 overwrite=false pifn_pref='picindex-' scale="auto" # HTML stuff folder_icon='' up_icon='' left_icon='' right_icon='' bgcolor="black" text_color="white" vlink_color="#aabbaa" link_color="#33aa11" ## ## Check for requirements ## for f in djpeg cjpeg rdjpgcom do if ! type $f >/dev/null 2>&1 then errecho "Cannot find required program: $f" errecho "Ensure it is installed and check the value of \$PATH in this script." exit 13 fi done ### ### Help ### function help { cat < $index_fn_tmp < $title

$title, page $ic of $num_pages

EOF # Link to one directory back. #if [[ -r ../${pifn_pref}1.html ]] #then up_dir=../`basename \`dirname $PWD\``/ echo "

$up_icon Up to $up_dir" >> $index_fn_tmp #fi # Create a link to each directory in this directory. if [[ -n $dirs ]] then echo '

' >> $index_fn_tmp for pd in $dirs do echo " ${folder_icon}$pd " >> $index_fn_tmp done echo '

' >> $index_fn_tmp fi # Start of Table for Picture HTML. cat >> $index_fn_tmp <
EOF ic=$(($ic + 1 )) done echo " " ############################## totalrow=0 c=0 ic=1 tn_dir=tn #bn=`basename $PWD` echo "\nProcessing images files in $PWD\c" while [[ $c -lt $num_files ]] do #################### # # If a non-zero picture.html file doesn't already exist, # Process each picture file like so: # 1) get dimensions # 2) create thumbnail # 3) generate picture.html page index_fn=${pifn_pref}${ic}.html # we use this temp files so that we can update something other than # the production file. (updates can take a long time!) index_fn_tmp=${index_fn}.tmp f=${jparray[c]} html_fn=$f.html nicename=`echo $f | sed 's/\..\{3,4\}$//'` newfile=${tn_dir}/tn-${f} # get the dimensions of the image infoline=`rdjpgcom -v $f | grep ^"JPEG image is" | sed 's/\*//g'` x=`echo $infoline | awk '{print $4}' | sed 's/w//'` y=`echo $infoline | awk '{print $5}' | sed 's/h,//'` dimension=$(($x * $y)) if [[ $dimension -lt 15000 ]] ; then scale=1 elif [[ $dimension -lt 150000 ]] ; then scale=2 elif [[ $dimension -lt 1500000 ]] ; then scale=4 elif [[ $dimension -gt 1500000 ]] ; then scale=8 fi if [[ ! -f $newfile ]] || [[ $f -nt $newfile ]] then mkdir -p $tn_dir >/dev/null 2>&1 if [[ $scale -ne 1 ]] ; then if ! djpeg -maxmemory 20m -scale 1/$scale $f | cjpeg -outfile $newfile then errecho "Command failed: djpeg -maxmemory 20m -scale 1/$scale $f | cjpeg -outfile $newfile" rm $newfile exit 11 fi else ln $f $newfile fi fi if [[ $scale -ne 1 ]] ; then tn_width=$(($x / $scale )) tn_height=$(($y / $scale )) else tn_width=$x tn_height=$y fi cell_width=$(( $tn_width + 10 )) # HTML for index file cat >> $index_fn_tmp < JPEG image of $f
$f EOF # Increment the width of the row (pixels), so we have some sort of # idea of when to start a new row. row_width=$(($row_width + $cell_width)) # Check to see if the row width is more than the threshhold and # wrap if it is. We just start a new table with each row, because # johan suspects this may be faster in some browsers. if [[ $row_width -gt $max_row_width ]] then row_width=0 cat >> $index_fn_tmp <

EOF fi # Only generate a picture.html if a non-zero one doesn't already exist. if [[ ! -s $html_fn ]] then prev=$(($c - 1)) next=$(($c + 1)) #################### # # HTML for the individual picture.html page. cat > $html_fn < $f

$f

JPEG image of $f

EOF # HTML to go to the previous picture if [[ $c -gt 0 ]] then cat >> $html_fn <${left_icon} Previous Picture EOF fi # HTML to go to the next picture if [[ -n ${jparray[next]} ]] then cat >> $html_fn <Next Picture ${right_icon} EOF fi # HTML to go to the the thumbnail page for this picture cat >> $html_fn <${up_icon} Back to $title EOF echo "+\c" else echo ".\c" fi # fi for check for already existant picture.html file. # If we have a full page of pics, increment the indexpage counter ($ic). # (We have to add one because $c is an index to the array elements, # which are number starting at 0, not 1.) if [[ $(( ($c+1) % $pics_per_page)) -eq 0 ]] then ic=$(($ic +1)) fi c=$(($c + 1)) # wait for djpeg to finish wait done echo " " # # End of processing for each individual picture. #################### ic=1 echo "Adding remaining html to index pages..." while [[ $ic -le $num_pages ]] do index_fn=${pifn_pref}${ic}.html # we use this temp files so that we can update something other than # the production file. (updates can take a long time!) index_fn_tmp=${index_fn}.tmp echo "$index_fn \c" cat >> $index_fn_tmp <

EOF # We only add links to other pages if there are other pages. if [[ $num_pages -gt 1 ]] then cat >> $index_fn_tmp < EOF # If this index page is not #1, create a "previous page" link. if [[ $ic -gt 1 ]] then pp=$(($ic - 1 )) cat >> $index_fn_tmp <${left_icon} Previous EOF fi # Create list of links to the other picture pages x=1 while [[ $x -le $num_pages ]] do if [[ $x -ne $ic ]] then cat >> $index_fn_tmp <${x} EOF else echo " $x " >> $index_fn_tmp fi x=$(($x + 1 )) done # If this index page is not the last, create a "next page" link. if [[ $ic -lt $num_pages ]] then np=$(($ic + 1 )) cat >> $index_fn_tmp <Next ${right_icon} EOF fi echo "" >> $index_fn_tmp fi # HTML for the footnote, the necessary wrap-up HTML for the index page. cat >> $index_fn_tmp <

$footnote


Created by $USER with $ME on $DATE. EOF mv $index_fn_tmp $index_fn ic=$(($ic + 1 )) done if [[ -f ${pifn_pref}1.html ]] && [[ ! -f index.html ]] then ln -s ${pifn_pref}1.html index.html fi echo " " # End of processing for thumbnail picture index page. #################### touch $timestamp_file