#!/bin/bash 

# Author: Hans-Henry Jakobsen
# Date: December 2007
# Homepage: http://pario.no
# E-mail: hanshj@pario.no

# Please give me a note if you find this little script usefull or make some fun changes to it.

# Description:
# Script to resize JPG images to desired width defined in IMAGESIZE variable.
# EXIF tags is also removed from the result images. 
# Software needed:
# jhead - http://www.sentex.net/~mwandel/jhead/ 
# imagemagick - http://www.imagemagick.org 

IMAGESIZE="320 480"
for IMAGEFILE in $(ls|grep JPG)
do
	for I in $IMAGESIZE 
	do
		# create directories if needed
		if [ ! -d $I ]
		then
			mkdir $I
		fi
	
		# Strip EXIF tag information from source file
		jhead -purejpg $IMAGEFILE

		# Resize file
		base=`basename $IMAGEFILE .JPG`_Resized_$I.JPG
		convert $IMAGEFILE -resize $I $base

		# Watermark the file
		width=`identify -format %w $base`
       	 	convert -background '#0008' -fill white -gravity center -size ${width}x15 \
        	-font Verdana -pointsize 10 \
	        caption:"Copyright © 2007 Pario.no" \
	        +size $base +swap -gravity south -composite $I/$base;
	
		# Delete resized image file
	        rm $base
	done
	
	# Delete source file
	rm $IMAGEFILE
done

