#! /bin/sh
convert=$(which convert)
prog="makethumbnail"
width="240"
height="80"

if [ ! "$convert" ]; then
    echo "$prog: nothing available command \"convert\"."
    exit 1
fi

while [ $# -gt 0 ]; do
    if [ -f $1 ] && [ -r $1 ]; then
	files="$files $1"
    else
	echo "no such file, ignore \"$1\"."
    fi
    shift
done

for f in $files; do
    body=${f%.*}
    ext=${f##*.}

    w240="${body}_w240.${ext}"
    h80="${body}_h80.${ext}"

    echo "generating $w240 ..."
    $convert $f -geometry $width $w240
    echo "generating $h80 ..."
    $convert $f -geometry x$height $h80
done

exit 0
