Created
September 22, 2017 22:45
-
-
Save auval/fb3334e2e6958c932c9b3ad67d7f81ec to your computer and use it in GitHub Desktop.
Add a timestamp watermark to photos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Change the font variable to point to your font location | |
#ok | |
font="/usr/share/fonts/truetype/lato/Lato-Thin.ttf" | |
#font="/home/amir/.local/share/fonts/Roboto-Light.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} | |
output=${filename}_DT.png | |
# 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/60)) | |
else | |
pointsize=$(($height/60)) | |
fi | |
# echo " Width: $width, Height: $height. Using pointsize: $pointsize" | |
#au: changing the date format | |
printed_date=`exiftool -DateTimeOriginal "$file" | sed -r 's#.*20([0-9]{2}):([0-9]{2}):([0-9]{2}).*#\2/\1#'` | |
#remove leading 0, if any | |
printed_date2=`echo $printed_date | sed 's/^0*//'` | |
#to date: | |
# date --date=`exiftool -DateTimeOriginal "AU(20120823_140042).JPG" | sed -r 's#.*([0-9]{4}):([0-9]{2}):([0-9]{2}).*#\1-\2-\3#'` | |
####works, but not used: | |
#bday=`date --date "20090823"` | |
#picdate=`date --date=\`exiftool -DateTimeOriginal "$file" | sed -r 's#.*([0-9]{4}):([0-9]{2}):([0-9]{2}).*#\1-\2-\3#'\`` | |
#age=$(( ( $(date -d "$picdate" +'%s') - $(date -d "$bday" +'%s') )/60/60/24/365 )) | |
#agem=$(( ( $(date -d "$picdate" +'%s') - $(date -d "$bday" +'%s') )/60/60/24/30 - 12*$age )) | |
#printed_date2=`echo ${printed_date}, ${age}y${agem}m | sed 's/^0*//'` | |
#### << works | |
# The real deal here | |
convert "$file" -gravity SouthEast -font "$font" -pointsize $pointsize -fill white -annotate +$pointsize+$pointsize "$printed_date2" "$output" | |
#exifftool | |
shift | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment