Skip to content

Instantly share code, notes, and snippets.

@pavlov99
Created July 22, 2018 06:40
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 pavlov99/4db640646b41f678777387d79e694296 to your computer and use it in GitHub Desktop.
Save pavlov99/4db640646b41f678777387d79e694296 to your computer and use it in GitHub Desktop.
Update incorrectly set image metadata in batch. Set geo location (latitude, longitude) and time.
#!/usr/bin/env bash
# Update photo information: time and location.
# After photo editing by agency, all of the meta tags were changed. This script fixes it.
# Photos are ordered by filename, e.g. 001.jpg, 002.jpg, etc. The whole event happened
# between 16:30 and 21:00 Moscow time on 30th June. Set time to every picture as if they were
# taken uniformly during the event.
#
# See also:
# exiftool https://www.sno.phy.queensu.ca/~phil/exiftool/ (allows batch editing as well).
# https://www.latlong.net/ to find your location and get latitude and longitude info.
FILENAMES=`find *.jpg -maxdepth 1 -type f`
DATETIME_BEGIN='TZ="Europe/Moscow" 2018-06-30T16:30:00'
DATETIME_END='TZ="Europe/Moscow" 2018-06-30T21:00:00'
DURATION=`echo "$(date --date="$DATETIME_END" +%s) - $(date --date="$DATETIME_BEGIN" +%s)" | bc`
NUMBER_FILES=`echo $FILENAMES | wc -w`
# Interval in seconds between two pictures
INTERVAL=`echo "$DURATION / $NUMBER_FILES" | bc`
count=0
t=`date --date="$DATETIME_BEGIN" +%s`
for filename in $FILENAMES; do
# For exiftool should be in correct format, e.g. 2018:06:30 16:30:00+03:00
dt=`TZ=":Europe/Moscow" date --date="@$t" '+%Y:%m:%d %H:%M:%S%:z'`
echo $filename, $dt
exiftool \
-copyright="©2018 Kirill Pavlov and Carrie Au. All rights reserved." \
-copyrightNotice="©2018 Kirill Pavlov and Carrie Au. All rights reserved." \
-xmp:dateTimeOriginal="$dt" \
-GPSLatitude="57.621096" -GPSLatitudeRef="North" \
-GPSLongitude="39.883492" -GPSLongitudeRef="East" \
$filename
(( t=t+$INTERVAL ))
(( count++ ))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment