#!/bin/sh
#
# resizephoto - this utility will resize photos from their original size
#    into a large, small and thumbnail size
#    putting them into the correct directories
#
# Dependencies - the "convert" program
#
# Author: Lawrence Folland
# Date: 2007/05/25
#
photo=$1

# Extract userid, truncate to 8-characters
userid=`echo $photo|cut -d. -f1|cut -d/ -f2|cut -c1-8`

# Look for the convert command (currently disabled)
#convertcmd=`which convert`

#if [ -z $convertcmd ]
#then
#   echo "convert utility not found"
#   exit 1
#fi

target=../large/$userid.jpg
echo "Creating large photo: $target"
convert -geometry 400x600 $photo $target
chmod a+r,g+w $target

target=../small/$userid.jpg
echo "Creating small photo: $target"
convert -geometry 120x180 $photo $target
chmod a+r,g+w $target

#
# thumbnails are special
#
target=../thumb/$userid.jpg

if [ -f $target -a ! -w $target ]; then
	echo WARNING: the thumbnail $target will not be updated mechanically,
	echo "  as it's quite possible that it was hand cropped."
	echo "  If you're absolutely *SURE* that it should be remade,"
	echo "  then add write permission and rerun this program."
else
	if [ -f $target ]; then
		echo Warning: remaking thumbnail $target
	else
		echo "Creating thumbnail: $target"
	fi
	convert -geometry 60x90 -crop 60x72+0+0  $photo $target
	chmod a+r,g+w $target
	cat <<EOF
If the thumbnail shows more than just the head and shoulders of the person,
the parameters used may have to change.
See ./00readme.txt for details.
EOF

fi

