#!/bin/sh maxwd=200 targetwd=170 find "$1" -type d | while read dir ; do firstimg=`ls -1 "$dir"/*.{png,jpg,jpeg,gif} 2> /dev/null | head -1` if [ -n "$firstimg" ]; then size=`identify "$firstimg" | sed -e 's/.*\(\<[0-9]\+x[0-9]\+\>\).*/\1/'` width="${size//[^0-9]*/}" height="${size//*[^0-9]/}" if [ "$width" -gt $maxwd ]; then targetht=$(( $height * $targetwd / $width )) destname="${firstimg##*/}" destname="00thumb_${destname%.*}.jpg" destpath=`dirname "$firstimg"` convert "$firstimg" -thumbnail ${targetwd}x$targht -antialias "$destpath/$destname" fi fi done