#!/bin/bash
# Script to add date & timestamp to lower right hand corner of jpeg images
# (where the date and timestamp is obtained from EXIF data if available)
#
# First (and only) argument is the file extension (jpg or JPG), and the output is in
# a file whose name is derived from the original name, stripped of the .jpg or .JPG
# extension, with "_anno.jpg" added
#
# requires exiv2
# 
# J. Amundson, 4-November-2008


for i in $( ls *.$1 ); do

TEXT=$(exiv2 $i | awk '/Image timestamp :/ {print $4, $5}' | sed 's/:/\//' | sed 's/:/\//')
[ -z "$TEXT" ] && exit 1
echo $TEXT

OUTPUT="$(basename "$i" "$1")_anno.jpg"

# use -pointsize 120  and -annotate +100+100 for hi-res glacier cam
# use -pointsize 30  and -annotate +100+10 for lo-res images (e.g. AWS)

convert $i -font /usr/share/fonts/truetype/freefont/FreeMono.ttf -fill white -gravity SouthEast -pointsize 150 -annotate +100+100 "$TEXT" "$OUTPUT"

done
