#!/bin/bash

src_dir=. 
dest_dir=/home/httpd/html/album/pictures
KDC2JPEG=kdc2jpeg

if [ ! -d "$src_dir/$1" ]; then
	echo "Usage:"
	echo "  make-images directory"
	exit 1
fi

umask 022
mkdir "$dest_dir/$1" 2>/dev/null

cat=`basename $1|cut -b 1-1`
case "$cat" in
	[01])
	collection_options="-g 2 +G"
	;;
	c)
	collection_options=""
	;;
	s)
	collection_options=""
	;;
	j)
	collection_options=""
	;;
	d)
	collection_options="-g 1.6"
	;;
	*)
	echo "collection type unrecognized '$cat'"
	;;
esac

global_options="+P $collection_options -C Chris.Studholme@canada.com"
thumbnail_options="-p -w 128 -h 128 -q 70"
little_options="-p -w 512 -h 480 -q 80"
big_options="-p -w 768 -h 600 -q 90"

for i in `ls "$src_dir/$1"|egrep '[.]kdc$|[.]tif*$|[.]jpe*g$'`; do
	
	if [ -r "$src_dir/$1/options" ]; then
		options_all="`grep '^ALL ' $src_dir/$1/options|sed 's/^ALL //'`"
		image_options="$options_all `grep $i $src_dir/$1/options|sed s/$i//`"
	else
	        image_options=""
	fi

	thumb_file="`echo $i|sed 's/[.][^.]*$/t.jpg/'`"
	little_file="`echo $i|sed 's/[.][^.]*$/l.jpg/'`"
	big_file="`echo $i|sed 's/[.][^.]*$/b.jpg/'`"

	echo
	$KDC2JPEG $global_options $image_options "$src_dir/$1/$i" $thumbnail_options "$dest_dir/$1/$thumb_file" $little_options "$dest_dir/$1/$little_file" $big_options "$dest_dir/$1/$big_file"

done
