Created
November 9, 2014 14:10
-
-
Save ilkerde/da62a981e3152f1b0591 to your computer and use it in GitHub Desktop.
REXIF - Fix EXIF data based on file name
This file contains hidden or 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 | |
files="*.jpg" | |
regex="IMG_([0-9]{4})([0-9]{2})([0-9]{2})_([0-9]{2})([0-9]{2})([0-9]{2}).*" | |
for f in $files; do | |
[[ $f =~ $regex ]] | |
y="${BASH_REMATCH[1]}" | |
m="${BASH_REMATCH[2]}" | |
d="${BASH_REMATCH[3]}" | |
hour="${BASH_REMATCH[4]}" | |
min="${BASH_REMATCH[5]}" | |
sec="${BASH_REMATCH[6]}" | |
exifdate=$(exiftool -ModifyDate -S $f) | |
filedate="ModifyDate: ${y}:${m}:${d} ${hour}:${min}:${sec}" | |
if [[ $exifdate == $filedate ]]; then | |
echo "EXIF [ OK ] $f" | |
else | |
echo "EXIF [ MISMATCH ] $f" | |
echo " Trying to fix EXIF data..." | |
exiftool -all= -tagsfromfile @ -all:all -unsafe $f | |
exiftool -ModifyDate="${y}:${m}:${d} ${hour}:${min}:${sec}" $f | |
echo " Done!" | |
echo "" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment