[add fotogirl Sven Moritz Hallberg **20100810213817 Ignore-this: 6f523880eb70f21db187f042ad2d5921 ] addfile ./fotogirl hunk ./fotogirl 1 +#!/bin/sh +# generate a html gallery from jpg's in current directory +# pesco 2010, isc license + +[ -z "$ssize" ] && ssize=1024 # major dimension of scaled images +[ -z "$tsize" ] && tsize=150 # edge len of thumbnails + +findfotos() { + find . -maxdepth 1 -type f -iregex '\./[^.].*\.jpe\{0,1\}g' \ + | sed -e 's:^\./::' +} + +n=`findfotos | wc -l | sed -e 's/ *//'` +if [ "$n" -eq 0 ]; then + echo "nothing to do, exiting" + exit +fi + +cat > index.html < + + + + +EOF + +# utility: auto-orient as necessary and return whether anything was done +do_autotran() { test -n "`exifautotran "$1"`"; } + +mkdir -p _scale +mkdir -p _thumb +i=1 +findfotos | sort | while read f; do + echo -n "[$i/$n] $f ..." + do_autotran "$f" && echo -n " (orient)" + w=`identify "$f" | sed -E 's/.*JPEG ([0-9]+)x([0-9]+).*/\1/'` + h=`identify "$f" | sed -E 's/.*JPEG ([0-9]+)x([0-9]+).*/\2/'` + + if [ "$w" -gt "$h" ]; then + # landscape + ws=$ssize + hs=`expr $ssize \* $h / $w` + wt=`expr $tsize \* $w / $h` + ht=$tsize + tx=0 + ty=`expr \( $ht - $tsize \) / 2` + else + # portrait + ws=`expr $ssize \* $w / $h` + hs=$ssize + wt=$tsize + ht=`expr $tsize \* $h / $w` + tx=`expr \( $wt - $tsize \) / 2` + ty=0 + fi + ss="${ws}x${hs}" + ts="${wt}x${ht}" + tg="${tsize}x${tsize}+${tx}+${ty}" + convert -scale $ss "$f" "_scale/$f" && echo -n " (scale)" + convert -scale $ts -crop $tg "$f" "_thumb/$f" && echo -n " (thumb)" + echo + printf '%s%s%s\n' "" \ + "$f" \ + "" >> index.html + i=`expr $i + 1` +done + +cat >> index.html <generated by +fotogirl, +(c) pesco 2010 + + +EOF