Last active
June 7, 2022 12:05
-
-
Save nanawel/baf17a1ff1354b79884e3f649b9cd09f to your computer and use it in GitHub Desktop.
Set or update OffsetTime and OffsetTimeOriginal EXIF tags on pictures using current timezone and pictures DateTimeOriginal
This file contains 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 | |
DIR="${DIR:-$1}" | |
OVERWRITE_EXISTING_TZ="${OVERWRITE_EXISTING_TZ:-0}" | |
ECHO_ONLY="${ECHO_ONLY:-0}" | |
[ ! -z "$DIR" ] || { echo -e >&2 "Usage:\n\t$0 <directory>"; exit 1; } | |
trap 'echo -e >&2 "\nCanceled."; exit 255;' INT | |
cmdPrefix="$([ $ECHO_ONLY = "1" ] && echo "echo" || echo "")" | |
IFS=$'\n'; for f in $(find "$DIR" -type f -iname "*.jpg"); do | |
file_date="$(exiftool -s -s -s -d '%Y-%m-%d %H:%M:%S' -DateTimeOriginal "$f")" | |
file_tz="$(exiftool -s -s -s -OffsetTime "$f")" | |
date_tz=$(date -d "$file_date" +%z | sed 's/\(.[0-9]\{2\}\)\([0-9]\{2\}\)/\1:\2/') | |
echo -n >&2 "$f => DATE=$file_date | TZ=$file_tz => " | |
if [ -z "$file_tz" ] || ([ "$file_tz" != "$date_tz" ] && [ "$OVERWRITE_EXISTING_TZ" = "1" ]); then | |
echo >&2 "Fix needed" | |
$cmdPrefix exiftool -OffsetTime="$date_tz" -OffsetTimeOriginal="$date_tz" $(printf %q "$f") | |
else | |
echo >&2 "OK" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment