Previously I talked about how to add date time stamp to your photos using completely free software. It was written mostly for Microsoft Windows users. The basic method should work on Mac, Linux, or other Unix flavors but there are obviously quite many differences between Windows batch file and shell scripts.
So I found sometime to create a shell script version to do just that for people who don’t use Windows. There is nothing fancy but it should work for typical users.
To get it started, follow the simple steps.
1. Install ImageMagick
How to do it is up to you. Personally I installed the MacPorts first, then installed ImageMagick by running a simple command “sudo port install ImageMagick” in a terminal on a Mac running Leopard. You can certainly try the pre-compiled binaries if you’d like.
2. Get the font
To make it look like the old 35mm point-and-shoot film camera’s time stamp, you can use a LCD font. Simply downloaded it and unpacked it somewhere. You don’t have to install the fonts. The script can work by a direct link to the font file location.
3. Get the code
The following is the complete shell script. Tested on a Mac running bash.
#!/bin/sh
# Change the font variable to point to your font location
font="/Users/max/Library/Fonts/digital-7 (mono).ttf"
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
# Work out a new file name by adding "_DT" before file extension
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 -font "$font" -pointsize $pointsize -fill white -annotate +$pointsize+$pointsize "%[exif:DateTimeOriginal]" "$output"
shift
done
exit 0
4. Do the work
Copy the code into a text editor, save it as “dtstamp.sh” or anything you like. Please note you need to change the 3rd line in the code to point to the font file location.
Run the following command to make it executable
chmod +x dtstamp.sh
To use it, simply run it like this
./dtstamp.sh directory/*.jpg
Or,
./dtstamp.sh file1.jpg file2.jpg...
After it runs, the script will produce files with “_DT” inserted between the original file name and file extension. The original file is unmodified.
Keywords: Date Time Stamp, exif, Metadata


