Based on http://dptnt.com/2009/08/add-date-time-stamp-to-jpeg-photos-using-free-software-mac-linux-nix-edition/ with some custom modification.
#!/bin/bash
if [ $# -eq 0 ]
then
cat << _EOF_
USAGE: $0 file1 file2 ..., or
$0 *.jpg, or
$0 dir/*.jpg
...
_EOF_
exit
fi
while [ "$1" != "" ]; do
# Skip directories
if [ -d "$1" ]; then
shift
continue
fi
# Skip already converted files (may get overwritten)
if [[ $1 == *_DT* ]]
then
echo "------ Skipping: $1"
shift
continue
fi
file=$1
echo "###### Working on file: $file"
filename=${file%.*}
extension=${file##*.}
output=${filename}_DT.${extension}
# Get the file dimension
dim=$(identify -format "%w %h" "$file")
width=${dim%% *}
height=${dim#* }
# Decide the font size automatically
if [ $width -ge $height ]
then
pointsize=$(($width/30))
else
pointsize=$(($height/30))
fi
echo " Width: $width, Height: $height. Using pointsize: $pointsize"
# The real deal here
convert "$file" -gravity SouthEast -pointsize $pointsize -fill white -annotate +$pointsize+$pointsize "%[exif:DateTimeOriginal]" "$output"
shift
done
exit 0
No comments:
Post a Comment