Last active
October 14, 2021 00:03
-
-
Save rootwork/85f22bb242657f9f22be2bc9639ccb57 to your computer and use it in GitHub Desktop.
Set a folder of images to have sequential dates in metadata based on filenames
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
# I had a directory of images that were alphabetized by file name, and I wanted | |
# to import them into a popular photo-printing service. I wanted to order them | |
# by filename, but this particular service only offered sorting by the date the | |
# photos were taken (forward or back). | |
# | |
# So I went about finding out how to create sequential creation dates for these | |
# photos' metadata based on their alphabetized file names. The actual date set | |
# didn't matter to me, because all I wanted them to be was in order. | |
# | |
# Note this is NOT a script to run, rather it's a series of commands and | |
# pointers to help in a similar situation. | |
## HOW TO ## | |
# Set all files to sequential (alphabetical) modified date | |
touch -a -m -- * | |
# Now space them apart by 5 milliseconds to ensure crappy photo software picks | |
# up on the differences | |
for i in *; do touch -r "$i" -d '-1 hour' "$i"; sleep 0.005; done | |
# Install exiftool if you don't have it already | |
sudo apt install exiftool | |
# Use exiftool to set "all dates" (which is only standard image | |
# creation/modification/access) to an arbitrary date, (P)reserving file | |
# modification date | |
exiftool -overwrite_original -P -alldates="2000:01:01 00:00:00" . | |
# Now update those dates sequentially separated one hour apart (it will kick | |
# over to the next day/month/year as necessary), going alphabetically by filename | |
exiftool -fileorder FileName -overwrite_original -P '-alldates+<${filesequence}0:0:0' . | |
# Update nonstandard "Date/Time Digitized" field to match creation date | |
exiftool -r -overwrite_original -P "-XMP-exif:DateTimeDigitized<CreateDate" . | |
# Update nonstandard and stupidly vague "Metadata Date" field to match creation | |
# date | |
exiftool -r -overwrite_original -P "-XMP-xmp:MetadataDate<CreateDate" . | |
## TOOLS ## | |
# check file dates | |
stat <FILE> | |
# check EXIF dates | |
exiftool <FILE> | grep "Date" | |
# check EXIF dates and get relevant field parameters | |
exiftool -a -G0:1 -time:all <FILE> | |
# clean up exiftool "_original" files if you've generated them | |
exiftool -delete_original <DIR> | |
# show EXIF problems for an individual file or all files in a directory | |
exiftool -validate -error -warning -a -r <FILE/DIR> | |
## REFERENCES ## | |
# https://askubuntu.com/questions/62492/how-can-i-change-the-date-modified-created-of-a-file | |
# https://www.thegeekstuff.com/2012/11/linux-touch-command/ | |
# https://unix.stackexchange.com/questions/180315/bash-script-ask-for-user-input-to-change-a-directory-sub-directorys-and-file | |
# https://photo.stackexchange.com/questions/60342/how-can-i-incrementally-date-photos | |
# https://exiftool.org/forum/index.php?topic=3429.0 |
This has been updated as an executable script and moved here:
https://github.com/rootwork/bash-scripts/blob/main/images/imagedate.sh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As part of this project, I also used the excellent Geeqie (
sudo apt install geeqie
) to sort out duplicates and pick the best (based on resolution, dimensions, etc.).Also, this:
is a nice one-liner to see if you have any identical images in a directory.