#!/bin/sh

usage()
{
  echo
  echo "usage: ${0} image-directory thumbnail-directory"
  echo
}

if ! [ ${1} ]
then
  usage
  exit 1
fi

if ! [ ${2} ]
then
  usage
  exit 1
fi

indir=${1}
outdir=${2}

if ! [ -d ${outdir} ]
then
  mkdir ${outdir}
fi

counter=0
for image in `find ${indir} -iname "*.jpg" -o -iname "*.png"`
do
  base=`basename $image`
  thumbnail="${outdir}/${base}"
  if ! [ -f ${thumbnail} ]
  then
    nice -n 19 convert ${image} -scale 320 ${thumbnail}
    counter=$(($counter+1))
  fi
done
echo "${0}: Created $counter new thumbnails"

# vim: tw=76 sw=2 ts=2 expandtab
