Skip to content

Instantly share code, notes, and snippets.

@eschmar
Last active August 15, 2020 12:38
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 eschmar/5d13969c9347cc473d9adbdc5fa82e12 to your computer and use it in GitHub Desktop.
Save eschmar/5d13969c9347cc473d9adbdc5fa82e12 to your computer and use it in GitHub Desktop.
Bash script to iterate over set of images, setting creation date
#!/bin/bash
# Whatsapp 'WhatsApp Image 2020-08-13 at 21.06.23.jpeg'
for file in ./*.jpeg; do
echo " > $file"
year=${file:17:4}
month=${file:22:2}
day=${file:25:2}
hour=${file:31:2}
minute=${file:34:2}
second=${file:37:2}
date="$year-$month-$day $hour:$minute:$second+02:00"
exiftool -overwrite_original -MediaCreateDate="$date" -CreateDate="$date" -TrackCreateDate="date" -DateTimeOriginal="$date" "$file"
mv "$file" "whatsapp_$year-$month-${day}_$hour-$minute-$second.jpg"
echo " -> date $year-$month-$day $hour:$minute:$second chosen."
done
DATE="2015-10-12"
# write creation date into EXIF meta data
for file in ./*; do
echo " > $file"
read -i "$DATE" -e DATE
exiftool -overwrite_original -DateTimeOriginal="$DATE 12:00:00+02:00" -CreateDate="$DATE 12:00:00+02:00" ${file}
echo " -> date $DATE chosen."
done
# MOV files have different keys..
for file in ./*.mov; do
echo " > $file"
read -i "$DATE" -e DATE
exiftool -overwrite_original -CreationDate="$DATE 12:00:01+02:00" -MediaCreateDate="$DATE 12:00:01+02:00" ${file}
echo " -> date $DATE chosen."
done
# PNG does not have exif date, change modified date with `touch`
for file in ./*.png; do
echo " > $file"
PNGDATE=$(exiftool -s -s -s -d "%Y%m%d%H%M.%S" -DateTimeOriginal ${file})
touch -t ${PNGDATE} ${file}
echo " -> date $PNGDATE chosen."
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment