#!/bin/sh # Width and height of thumbnail page w=1024 h=768 # Width, height and margin of thumbnail tw=128 th=128 tm=15 # Vertical upwards adjustment to leave space for text label vadj=16 # Vertical spacing between thumbnail and text tspc=6 tm2=$(($tm * 2)) nt_h=$(($w / ($tw + $tm2))) nt_v=$(($h / ($th + $tm2))) tmadd_h=$((($w - (($tw + $tm2) * $nt_h)) / $nt_h)) tmadd_v=$((($h - (($th + $tm2) * $nt_v)) / $nt_v)) tm_h=$(($tm + ($tmadd_h / 2))) tm_v=$(($tm + ($tmadd_v / 2))) tw_tot=$(($tw + $tm2 + $tmadd_h)) th_tot=$(($th + $tm2 + $tmadd_v)) tmpfile1=$(mktemp ~/.mkthumb.XXXXXX) || exit 1 tmpfile2=$(mktemp ~/.mkthumb.XXXXXX) || exit 1 tmpfile3=$(mktemp ~/.mkthumb.XXXXXX) || exit 1 tmpfile4=$(mktemp ~/.mkthumb.XXXXXX) || exit 1 tlead=$(mktemp ~/.mkthumb.XXXXXX) || exit 1 pbmmake -black 1 6 >$tlead rm -f [0-9][0-9][0-9]thumb.??? exec 2>/dev/null x=0; y=0 n=1; tfile=$(printf "%03dthumb.ppm" $n) mkjbginfo info=$(cat .jbginfo) oifs="$IFS"; IFS=" " for r in $info; do IFS="$oifs" f=${r%% *}; title=${f%.jbg}; r=${r#* } [ ! -f "$f" ] && continue xres_o=${r%% *}; r=${r#* } yres_o=${r%% *} jbgtopbm "$f" | pnmscale -xysize $tw $th >$tmpfile1 || continue res=$(pnmfile $tmpfile1 | nawk '{print $4 " " $6}') xres=${res% *}; yres=${res#* } pbmtext "$title" | pnmcrop -white | pnminvert >$tmpfile3 pbmtext ${xres_o}x${yres_o} | pnmcrop -white | pnminvert >$tmpfile4 tres=$(pnmfile $tmpfile3 | nawk '{print $4 " " $6}') txres=${tres% *}; tyres=${tres#* } if [ $txres -gt $tw ]; then pnmcut 0 0 $tw $tyres $tmpfile3 >$tmpfile2 mv -f $tmpfile2 $tmpfile3 txres=$tw fi tres=$(pnmfile $tmpfile4 | nawk '{print $4 " " $6}') txres2=${tres% *}; tyres=${tres#* } if [ $txres2 -gt $tw ]; then pnmcut 0 0 $tw $tyres $tmpfile4 >$tmpfile2 mv -f $tmpfile2 $tmpfile4 txres=$tw fi [ $txres2 -gt $txres ] && txres=$txres2 pnmcat -tb -black $tmpfile3 $tlead $tmpfile4 >$tmpfile2 colfile=$(mktemp ~/.mkthumb.XXXXXX) || exit 1 ppmmake black $tw_tot $th_tot | \ pnmpaste $tmpfile1 $(($tm_h + (($tw - $xres) / 2))) \ $(($tm_v + (($th - $yres) / 2) - $vadj)) | \ pnmpaste $tmpfile2 $(($tm_h + (($tw - $txres) / 2))) \ $(($tm_v + (($th - $yres) / 2) + $yres - $vadj + $tspc)) >$colfile colfiles="$colfiles $colfile" x=$(($x + $tw_tot)) if [ $(($x + $tw_tot)) -gt $w ]; then rowfile=$(mktemp ~/.mkthumb.XXXXXX) || exit 1 pnmcat -lr -black $colfiles >$rowfile rowfiles="$rowfiles $rowfile" rm -f $colfiles colfiles= x=0; y=$(($y + $th_tot)) if [ $(($y + $th_tot)) -gt $h ]; then pnmcat -tb -jleft -black $rowfiles >$tfile rm -f $rowfiles rowfiles= y=0 n=$(($n + 1)); tfile=$(printf "%03dthumb.ppm" $n) fi fi done if [ -n "$colfiles" -o -n "$rowfiles" ]; then if [ -n "$colfiles" ]; then rowfile=$(mktemp ~/.mkthumb.XXXXXX) || exit 1 pnmcat -lr -black $colfiles >$rowfile rowfiles="$rowfiles $rowfile" fi pnmcat -tb -jleft -black $rowfiles >$tfile fi for f in [0-9][0-9][0-9]thumb.ppm; do if ! [ -f "$f" ]; then continue; fi ppmquant 8 $f | ppmtogif >${f%.ppm}.gif rm -f $f done rm -f $tmpfile1 $tmpfile2 $tmpfile3 $tmpfile4 $tlead $colfiles $rowfiles .