#!/bin/sh # # thumbnail_index - make an index.html file with image thumbnails # # Run this script in a web directory consisting of all or mostly image # files. It'll create an index.html of thumbnail images, putting # the thumbnail files in a hidden subdirectory. # # It avoids unnecessary work by comparing the dates on already existing # thumbnail files and not re-creating them if the corresponding original # has not changed. # # It also refuses to overwrite an index.html file not created by this script. # # (C) 1995,1996 by Jef Poskanzer . All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # # Enhancement by Yoichi Hariguchi. # # 1. Slide Show (01/04/2005) # 2. Back, Forward, and Back-to-Thumbnails buttons # 3. Captions. Create .captions file in the same directory in a web # directory consisting of all image files. Each line of the .caption # file must have the following format: # # # # Note that the separator between the file name and the caption must # be the TAB character (just like makefile ;-) (03/30/2003) # 4. If you have a small size picture directory (e.g. for access via web) # in addition to the original size picture directory, this program # can make a small picture a link to the original picture. # The name of the default original picture directory is "raw", # but it can be changed with the "-d" command line option. # You can use "http://www.hariguchi.org/software/mksmallpic.sh" # to make small pictures from the original size pictures. (03/09/2006) # 5. If you have a file called ".comments" in the current directory, # the content of the file is included right below the title. You can # write any HTML statements in the file. (04/04/2006) # # # Output Examples are available at http://www.aya.us/ # # $Id: ti,v 1.19 2006/04/05 00:17:49 yoichi Exp $ # # Defaults. recurse=no size=70 bigsize=1280 colsperrow=5 rowspertable=10 indexname=index.html captionname=.captions commentname=.comments title="Index of `pwd | cut -d'/' -f 4-`/" usage="usage: `basename $0` [-r] [-s size] [-c cols] [-i indexname] [-d dir] [-t title]" refresh=5 ss_html="_ss.html" # slide show html file suffixes="$ss_html .html" prefix="s_" # prefix of small pictures origPicDir="raw" # directory for original size pictures # Parse args. while true ; do case "$1" in -r ) recurse=yes shift ;; -s ) shift if [ $# -eq 0 ] ; then echo $usage >&2 exit 1 fi size="$1" shift ;; -c ) shift if [ $# -eq 0 ] ; then echo $usage >&2 exit 1 fi colsperrow="$1" shift ;; -i ) shift if [ $# -eq 0 ] ; then echo $usage >&2 exit 1 fi indexname="$1" shift ;; -d ) shift if [ $# -eq 0 ] ; then echo $usage >&2 exit 1 fi origPicDir="$1" shift ;; -t ) shift if [ $# -eq 0 ] ; then echo $usage >&2 exit 1 fi title="$1" shift ;; -* ) echo $usage >&2 exit 1 ;; * ) break ;; esac done if [ $# -ne 0 ] ; then echo $usage >&2 exit 1 fi subdir=.thumbnails nindexname=/tmp/tinind.$$ stamp='This file produced by thumbnail_index - do not edit.' cwd=`pwd` makefile=/tmp/timake.$$ infoscript=/tmp/tiinsc.$$ rm -f $nindexname $makefile $infoscript if [ -f "$indexname" ] ; then if egrep -s "$stamp" "$indexname" > /dev/null 2>&1 ; then echo > /dev/null # Why the fuck doesn't an empty command work?? else echo "thumbnail_index: $indexname exists, not produced by this script" >&2 exit 1 fi fi # Make temporary script to extract info. cat > $infoscript << 'EOF' #!/bin/sh file="$1" what="$2" thumb="$3" kb=`wc -c < "$file" | awk '{print int(($1+1023)/1024)}'` # (Slower but more portable than using ls.) set junk `"$what" "$file" | pnmfile` ; shift width=$4 height=$6 set junk `djpeg "$thumb" | pnmfile` ; shift twidth=$4 theight=$6 echo "$kb" "$width" "$height" "$twidth" "$theight" EOF chmod 755 $infoscript if [ ! -d $subdir ] ; then mkdir $subdir fi ( if [ ! -f $subdir/.parent.gif ] ; then ( cd $subdir cat << 'EOF' | uudecode begin 644 .parent.gif M1TE&.#EA%``6`(```````/___R'Y!`$```$`+``````4`!8```(VC(^I".L' MVENQQFFLKG3[FWVB-'Y0N9UH(X6,YC))&UA8[4VCPXI/R'AU]?7U%141L;&\S,S`T-#;Z^OK"PL'IZ M>FQL;$1$1#8V-B@H*````"P`````2@`8```$X]#(2:N]..O-N_]@*(YD:9YH MJJYLZ[XIT@"T5!O'8=V;3`,VH,L!"%!X%V2&:)PH533$47A#$`]5`HTAG7:# MAH9#(4$PME*L=*"3:+\3;*%IN-UFB\1M`%@(``P5!QG&*QKVZEPC&J!4-LUNNS,1`#L` ` end EOF ) fi if [ ! -f $subdir/.forward.gif ] ; then ( cd $subdir cat << 'EOF' | uudecode begin 644 .forward.gif M1TE&.#=A&``8`/,``++`W`("`AH:&G>=;8BN@)>WBYZZDNGOZ#Q9-@`````` M`````````````````````"P`````&``8```$2Q#(2:N]..O-N_]6$(#A(9)3 M<*PGJ:[L^+UP[-'U*LB:D.>&%B9@(!B/A,$`(;P0DHV)```[ ` end EOF ) fi if [ ! -f $subdir/.index.gif ] ; then ( cd $subdir cat << 'EOF' | uudecode begin 644 .index.gif M1TE&.#EA&``8`,(``````,S,S)65E?___\S,_____________RP`````&``8 M```#2!BZW/XPRDEK!!BTK"4@8*=\H4<,A!A\J.JPZ3J>L;N0\0WF$*?ZEJ!P A2!QE-D=32;?LT7Y/4TNVBMIFS6KVQ6$`B^"P>`Q.```[ ` end EOF ) fi if [ ! -f $subdir/.pause.gif ] ; then ( cd $subdir cat << 'EOF' | uudecode begin 644 .pause.gif M1TE&.#=A,``8`)$``````.[N[O___P```"P`````,``8```"6(R/J;J E27.<<,SDD)E:.GW5ZD^;F.*(0^B,C$JKU^RV^PV/3P3R1@$`.P`` ` end EOF ) fi if [ ! -f $subdir/.censored.png ] ; then ( cd $subdir cat << 'EOF' | uudecode begin 644 .censored.png MB5!.1PT*&@H````-24A$4@```4````"@`0,```!';2??````!E!,5$7___\` M``!5PM-^`````7123E,`0.;89@```PU)1$%4>)SMUSUNVS`4`.`G"`@70UHS M$.(5,C*H8%W%O0&+#%4!HU(NT%X@!^G(PD.WGH%!AJXLNG!0S/+1<6O3D4@' M'=I";S%,?[:LI\>?!S#'''.\)$J9"!N="*U)01LOM"58J$1812*%N*<+8E*B@K6N$)`)9 MIIGQL)^&I56E1ICW^20D5A+I?S%6FMO]-U)KN(!(09X-*<0*\GQXF0:C=7LV MO$J%<_Q]\8?+H;3;5&CY?OX=+GPG4Y((233<.**+X;[M>P`ALO; M#C8]K`+8G$)#,MO#-RER98WB*^U67S\4P.N!Y#]ZL$J4!N&-<0<2/Q3`5UM" M-@YJP89.*]Z9SH`?"F#S@9"L!R-$71-PD+>%'BF]$.GD+B-SA4%TP0Z![$HR#:`"X28$"L%D1?0?!+` ML,S"A/^*L/Y&0R6Z&<[Q3\?KSW+DD]7QV_LQ6`;KX"ADJ;!+A285ZJ`]&8.9 M2H3[WK6.P:=5\/>2-`I=@GJW30[8;^8:UF.P=`E2-X;=8;]9#ID=@^XX;_5; MLZ38;[)M/@6U[BA?8+]9560S!BO(I'Y/.6"_R2LR>C,4LHU:TZ;'?I.ORPF8 M?Y0M90K[S3>FF((66EH:;/HZ-0D-"`H[")-0(O0=;#L!*WCH+QWT_:;(QV&1 M/4@NZ(IBO]FZK4D]R]PC)/?:".K:3==O+AG9C$%B;]V!AW8&^\T&'^%M_RQT MR>F4H(W&?A.+XOOHG'&GM2M:*NPWW1'F_?@"$(9,A7/,, $title

$title

EOF if [ -f "$commentname" ]; then cat "$commentname" echo "


" fi cat << EOF

EOF row=0 col=1 prev='' html='' for file in * ; do if [ "$col" -ge "$colsperrow" ] ; then col=0 row=`echo $row + 1 | bc` if [ "$row" -ge "$rowspertable" ] ; then row=0 echo "
Parent dir
" else echo "" fi fi case "$file" in "$indexname") what=SKIP ;; *.gif) ext=.gif ; what='giftopnm' ;; *.GIF) ext=.GIF ; what='giftopnm' ;; *.jpg) ext=.jpg ; what='djpeg' ;; *.JPG) ext=.JPG ; what='djpeg' ;; *.jpeg) ext=.jpeg ; what='djpeg' ;; *.JPEG) ext=.JPEG ; what='djpeg' ;; *.tif) ext=.tif ; what='tifftopnm' ;; *.tif.Z) ext=.tif.Z ; what='(zcat|tifftopnm)' ;; *.tiff) ext=.tiff ; what='tifftopnm' ;; *.tiff.Z) ext=.tiff.Z ; what='(zcat|tifftopnm)' ;; *.r) ext=.r ; what='rasttopnm' ;; *.r.Z) ext=.r.Z ; what='(zcat|rasttopnm)' ;; *.x) ext=.x ; what='xbmtopbm' ;; *.x.Z) ext=.x.Z ; what='(zcat|xbmtopbm)' ;; *.xbm) ext=.xbm ; what='xbmtopbm' ;; *.xbm.Z) ext=.xbm.Z ; what='(zcat|xbmtopbm)' ;; *.xwd) ext=.xwd ; what='xwdtopnm' ;; *.xwd.Z) ext=.xwd.Z ; what='(zcat|xwdtopnm)' ;; *.fs) ext=.fs ; what='fstopgm' ;; *.fs.Z) ext=.fs.Z ; what='(zcat|fstopgm)' ;; *.pbm) ext=.pbm ; what='cat' ;; *.pbm.Z) ext=.pbm.Z ; what='zcat' ;; *.pgm) ext=.pgm ; what='cat' ;; *.pgm.Z) ext=.pgm.Z ; what='zcat' ;; *.ppm) ext=.ppm ; what='cat' ;; *.ppm.Z) ext=.ppm.Z ; what='zcat' ;; *.pnm) ext=.pnm ; what='cat' ;; *.pnm.Z) ext=.pnm.Z ; what='zcat' ;; *~) ext=~ ; what='SKIP' ;; *) what=FILE ;; esac case $what in SKIP) continue ;; FILE) if [ -d "$file" ] ; then if [ ! -f $subdir/.folder.gif ] ; then ( cd $subdir cat << 'EOF' | uudecode begin 644 .folder.gif M1TE&.#EA%``6`,(``````)EF,S,S,\S____,F0```````````"'Y!`$```,` M+``````4`!8```-4.+K<_C#*21FX^$Y`NN]`Q'UDIBE`0'IJB1)!+,%Q9SRR@DXB--I)4F%6F%;%W<)X@]1L/!:`P^:T>LT3 (+$SPC#L!`#L% ` end EOF ) fi nf=`ls "$file" | egrep -v "$indexname" | wc -l | awk '{print $1}'` echo "" if [ $recurse = yes ] ; then echo "$file/" >&2 ( cd "$file" ; thumbnail_index -r -s "$size" -c "$colsperrow" -i "$indexname" ) fi else if [ ! -f $subdir/.file.gif ] ; then ( cd $subdir cat << 'EOF' | uudecode begin 644 .file.gif M1TE&.#EA%``6`,(``````)F9F3,S,\S______P```````````"'Y!`$```,` M+``````4`!8```-0*+J\\W`(0JN=(KYI.\\1UU4BN(W7!8DH(+CPB5)`;0/R M3`5\@$LZ2^_'"A)\.>.1J*P@@:_(;
$file/
${nf} files
$file
${kb}K
" fi ;; *) thumb=$subdir/`echo "$file" | sed "s/$ext\$/_t.jpg/"` if [ -f "$thumb" -a ! -s "$thumb" ] ; then rm -f "$thumb" fi info=$subdir/`echo "$file" | sed "s/$ext\$/_t.info/"` if [ -f "$info" -a ! -s "$info" ] ; then rm -f "$info" fi cat << EOF > $makefile all: $thumb $info $thumb: $file @echo "$file" >&2 @$what "$file" | pnmscale -xy "$size" "$size" | cjpeg > "$thumb" $info: $thumb @$infoscript "$file" "$what" "$thumb" > "$info" EOF make -f $makefile | egrep -v 'is up to date' >&2 rm -f $makefile set junk `cat "$info"` ; shift kb="$1" width="$2" height="$3" twidth="$4" theight="$5" next=`echo "$file" | sed 's/\..*$//'` if [ "$html" ]; then for suffix in $suffixes do sed "s%%%" \ $subdir/${html}${suffix} > /tmp/${html}${suffix} mv /tmp/${html}${suffix} $subdir/${html}${suffix} echo "" >> $subdir/${html}${suffix} if [ $suffix = $ss_html ]; then echo "" >> $subdir/${html}${suffix} else echo "" >> $subdir/${html}${suffix} fi cat << 'EOF' >> $subdir/${html}${suffix}


Produced by enhanced thumbnail_index. The original software is here. EOF done sed "s%%%" $subdir/${html}${ss_html} > /tmp/${html}${ss_html} mv /tmp/${html}${ss_html} $subdir/${html}${ss_html} prev=$html fi html=$next for suffix in $suffixes do cat << 'EOF' > $subdir/${html}${suffix} EOF echo "$file" >> $subdir/${html}${suffix} cat << 'EOF' >> $subdir/${html}${suffix} EOF if [ "$prev" ]; then echo " " >> $subdir/${html}${suffix} else echo " " >> $subdir/${html}${suffix} if [ $suffix = "$ss_html" ]; then cat << 'EOF' > $subdir/slideshow.html >> $subdir/slideshow.html cat << 'EOF' >> $subdir/slideshow.html EOF fi fi if [ -f "$captionname" ]; then caption=`egrep "$file" $captionname | cut -d' ' -f 2` if [ "$caption" ]; then caption=" --- $caption" fi fi cat << EOF >> $subdir/${html}${suffix} EOF if [ $suffix = $ss_html ]; then echo "" >> $subdir/${html}${suffix} else echo "" >> $subdir/${html}${suffix} fi if [ "$width" -gt "$bigsize" ]; then disp_width=$bigsize else disp_width=$width fi cat << EOF >> $subdir/${html}${suffix} $caption
EOF if ls -l $file | cut -f 1 -d ' ' | egrep '.......-..' >/dev/null ; then echo "" >> $subdir/${html}${suffix} else origFile=`echo $file | sed "s/$prefix//"` if [ -f $origPicDir/$origFile ]; then echo "" >> $subdir/${html}${suffix} else echo "" >> $subdir/${html}${suffix} fi fi cat << EOF >> $subdir/${html}${suffix}

EOF if [ "$prev" ]; then echo " " >> $subdir/${html}${suffix} else echo " " >> $subdir/${html}${suffix} fi echo " " >> \ $subdir/${html}${suffix} done if [ "$width" -le "$size" -a "$height" -le "$size" ] ; then echo "
$file
${kb}K ${width}x${height}
" elif [ "$width" -ge "$bigsize" ]; then echo "
$file
${kb}K ${width}x${height}
" else echo "
$file
${kb}K ${width}x${height}
" fi ;; esac col=`echo $col + 1 | bc` done if [ "$html" ]; then for suffix in $suffixes do sed "s%%%" \ $subdir/${html}${suffix} > /tmp/${html}${suffix} mv /tmp/${html}${suffix} $subdir/${html}${suffix} echo "" >> $subdir/${html}${suffix} if [ $suffix = $ss_html ]; then echo "" >> $subdir/${html}${suffix} else echo "" >> $subdir/${html}${suffix} fi cat << 'EOF' >> $subdir/${html}${suffix}
Produced by enhanced thumbnail_index. The original software is here. EOF done sed "s%%%" $subdir/${html}${ss_html} > /tmp/${html}${ss_html} mv /tmp/${html}${ss_html} $subdir/${html}${ss_html} fi cat << 'EOF'
Index produced by enhanced thumbnail_index. The original software is here. EOF ) > $nindexname rm -f "$indexname" cp $nindexname "$indexname" rm -f $nindexname $infoscript