Skip to content

Instantly share code, notes, and snippets.

@Tabea-K
Last active February 19, 2019 12:34
Show Gist options
  • Save Tabea-K/4d36e230019cb003eb4f774157e3abe9 to your computer and use it in GitHub Desktop.
Save Tabea-K/4d36e230019cb003eb4f774157e3abe9 to your computer and use it in GitHub Desktop.
This is a small script to modify the JPEG metadata of photos downloaded from WhatsApp. Usually, the downlaoded pictures will have set the "DateTimeOriginal" to the date they were downloaded, not when they were taken. This is unfortunate, if you for example want to upload them to google photos as they will be sorted incorrectly by date. To fix th…
#!/bin/bash
# This small script can set the exif metadata of a jpeg file
# to the date and time given in the file name assigned by WhatsApp
# when downloading the image.
# The filename needs to be in a format like this (the automatically assigned
# format as of 2019-02-12):
# "WhatsApp Image 2018-09-20 at 17.18.42.jpeg"
# In order to modify all jpeg files in a folder,
# run the command like this:
# for F in *.jpeg
# do
# ./correct_WhatsApp_picture_exifdate.sh "$F"
# done
#
# Don't forget the quotes around the file name, as the
# filename contains blanks!
INFILE="$1"
YMD=$(echo "$INFILE" | cut -f3 -d " ")
DATE=$(echo "$YMD" | cut -f3 -d"-")
YEAR=$(echo "$YMD" | cut -f1 -d"-")
MONTH=$(echo "$YMD" | cut -f2 -d"-")
DAY=$(echo "$YMD" | cut -f3 -d"-")
TIME=$(echo "$INFILE" | cut -f5 -d" " | cut -f1,2,3 -d"." | tr "." ":")
echo "Will set original time and date of file $INFILE to ${YEAR}:${MONTH}:${DAY} ${TIME}!"
exiftool "-DateTimeOriginal=${YEAR}:${MONTH}:${DAY} ${TIME}" "${INFILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment