Skip to content

Instantly share code, notes, and snippets.

@crossle
Forked from unabridgedxcrpt/EXIFdate2photo.sh
Last active February 19, 2017 03:25
Show Gist options
  • Save crossle/9fef38b9c019def0029d0e02d909e8a2 to your computer and use it in GitHub Desktop.
Save crossle/9fef38b9c019def0029d0e02d909e8a2 to your computer and use it in GitHub Desktop.
Grab the EXIF date from original date time field and overlay it on a photo with white text with black stroke font.
#!/bin/sh
#Credit: http://dptnt.com/2009/08/add-date-time-stamp-to-jpeg-photos-using-free-software-mac-linux-nix-edition/
# I added:
# 1. formatting the EXIF date to use the month name and remove the seconds from the time display
# 2. outline the text for lighter backgrounds and better contrast in more images.
#Dependencies: imagemagick, exiftool
# Change the font variable to point to your font location
##font="~/Library/Fonts/digital-7 (mono).ttf"
## digital 7 for to make date time like the *olden days*: http://www.dafont.com/digital-7.font
font="/Library/Fonts/Arial Black.ttf"
## really big system font for sight-impaired relatives :)
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, 30 is usually good, but I needed it larger
if [ $width -ge $height ]
then
pointsize=$(($width/75))
else
pointsize=$(($height/75))
fi
echo " Width: $width, Height: $height. Using pointsize: $pointsize"
exifdate=`exiftool -d " %Y-%m-%d %H:%M:%S " -FileModifyDate -S -s "${file}"`
echo "------ $exifdate" #sanity check in processing
# The real deal here
convert "$file" -gravity SouthEast -font "$font" -pointsize $pointsize -fill white -stroke black -strokewidth 4 -annotate +$pointsize+$pointsize "$exifdate" -stroke none -annotate +$pointsize+$pointsize "$exifdate" "$output"
shift
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment