autothumbs.sh: a thumbnails-script


a BASH script to make thumbnails from pictures. Reqiures the imagemagick program ( apt-get install imagemagick )

Copy the code, or download the script. Remember to make it executable ( chmod 755 ./autothumbs.sh )

#!/bin/sh
# inputs_marmalade's modification of a script written by
# katja socher 
# and guido socher 
# licensed under GPL ver.2: http://www.gnu.org/licenses/gpl-2.0.html


help()
{
    cat <<HELP
        autothumbs -- generate thumbnails from image files

USAGE: autothumbs [-h]  image1 image2 ...

OPTIONS: -h this help

EXAMPLE: autothumbs *.gif

HELP
   exit 0
}
error()
{
    echo "$1"
    exit "$2"
}
while [ -n "$1" ]; do
case $1 in
    -h) help;shift 1;;
    --) break;;
    -*) echo "error: no such option $1. -h for help";exit 1;;
    *)  break;;
esac
done

if [ -z "$1" ];then
    error "No image specified, -h for help" 1
fi

# width and height of thumbnails
echo "Enter the maximal WIDTH x maximal HEIGHT"
echo "of the new thumbnails (ex: 200x100)"
read response

# process each image
i=0
for imgfile in $* ;do
    if [ ! -r "$imgfile" ]; then
        echo "ERROR: can not read $imgfile\n"
    else
        i=`expr $i + 1`
        bn=`basename "$imgfile"`
        dn=`dirname "$imgfile"`
        if echo "$bn" | grep "^t_" > /dev/null ; then
           echo ""
           continue
        fi
        tumbnailfilename="$dn/thumb_$bn"
        convert -geometry "$response" "$imgfile" "$tumbnailfilename"
fi
done