#! /bin/sh

case $# in
0) echo Usage: $0 "filename(s)" 
   echo Example: $0 "*.JPG"
   exit 1;
   ;;
*) if [ -r ~/.magick ] 
   then
     source ~/.magick
   fi
   ;;
esac

RESIZE=./resize
BYTES=524228
#BYTES=4193824

if [ -d $RESIZE ]
then
  echo "Files will be copied to $RESIZE"
else
  mkdir $RESIZE
  echo "Directory $RESIZE created"
  echo "Files will be copied to $RESIZE"
fi

for i
do
name=`printf %s ${i}`
root=$name
root=`printf %s $root | sed -e s/\.jpg//`
root=`printf %s $root | sed -e s/\.JPG//`
root=`printf %s $root | sed -e s/\.jpeg//`
root=`printf %s $root | sed -e s/\.jpg//`
convert $name -resize ${BYTES}@ $RESIZE/${root}_resize.JPG
case $? in
  0) printf "%s\n" "File ${name} sized to $BYTES as $RESIZE/${root}_resize.JPG"
     ;;
  *) printf "%s\n" "File ${name} resize failed"
     ;;
esac
done

case $? in
  0) exit 0; 
     ;;
  *) exit 1;
     ;;
esac
