Skip to content

Instantly share code, notes, and snippets.

@twidi
Created September 16, 2016 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twidi/016ab06c94a32502d5de153ddcc337c7 to your computer and use it in GitHub Desktop.
Save twidi/016ab06c94a32502d5de153ddcc337c7 to your computer and use it in GitHub Desktop.
Script used to update each image for my plant timelapse https://www.youtube.com/watch?v=_WLxC3imytk
#! /bin/bash
# This script expect a image file as first argument, and a destination directory as second.
# It will:
# - rotate the image 0.4deg
# - crop to a ratio for HD (1920*1080)
# - add the timestamp in the top right corner
# This timestamp is in the format "xXh yYm", and computed from a time of the day extracted from the first image
# of the directory. All images are the same day, so it's easier.
# It's printed in white with a soft black shadow.
# Used with parallel: parallel -j 8 'prepare-img.sh "source/{}" prepared' ::: *.JPG
FILE=$1
DEST_DIRECTORY=$2
echo_stderr ()
{
echo ERROR: "$@" >&2
}
if [ ! -f "$FILE" ]
then
echo_stderr "The given file does not exist"
exit 1
fi
if [ ! -d "$DEST_DIRECTORY" ]
then
echo_stderr "The given directory does not exist or is not a directory"
exit 1
fi
TIME=$(exif -m -t DateTimeOriginal "$FILE" | cut -d ' ' -f2)
HOUR=$(echo $TIME | cut -d : -f1)
MINUTE=$(echo $TIME | cut -d : -f2)
SECOND=$(echo $TIME | cut -d : -f3)
DELTA_FIRST=44775 # 12h26mn15s (time of first image) in seconds
DELTA=$(bc <<< "$HOUR*3600+$MINUTE*60+$SECOND-$DELTA_FIRST")
DELTA_HOUR=$(bc <<< "$DELTA/3600")
DELTA_MINUTE=$(bc <<< "($DELTA%3600)/60")
DELTA_PRINT=$(printf "%2dh %2dm" $DELTA_HOUR $DELTA_MINUTE)
convert -size 550x300 xc:none -gravity northwest -pointsize 150 -stroke none -strokewidth 0 -annotate 0 "$DELTA_PRINT" -background none -shadow 40x5+0+0 +repage -stroke none -fill white -annotate 0 "$DELTA_PRINT" \( -rotate 0.4 +repage -crop 4562x2566+20+867 $FILE \) +swap -gravity northeast -geometry +100+100 -composite "$DEST_DIRECTORY"/"$FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment