Skip to content

Instantly share code, notes, and snippets.

@MadLittleMods
Last active July 29, 2022 03:08
Show Gist options
  • Save MadLittleMods/4e0d9b9b4edb6bd24d6a88aac32100ed to your computer and use it in GitHub Desktop.
Save MadLittleMods/4e0d9b9b4edb6bd24d6a88aac32100ed to your computer and use it in GitHub Desktop.
Fix photos sorted in maddening wrong order by date

Problem

We were dealing with an out of order dump of photos from a Google photos album and wanting to upload to Facebook. It consisted of jpg and heic photos from a iPhone 8 and Pixel 4a so the metadata was different.

Sorting by Date Created in the macOS finder was out of order and Facebook seemed to sort in the same way. It didn't make any sense because we were seeing 4:55am photos sorted below 4:56pm photos (same day). Regardless of Italian timezone, they shouldn't be sorting like that (it's only GMT+2 vs my local GMT-6) which is an 8 hour difference compared the 12 hour difference shown in the photo date/times. Even looking at the exif metadata, it didn't make any sense what it was pulling from to make it sort that way.

Solution

This uses exiftool to read and do the file manipulation.

  • Get rid of all of the date related exif fields
  • Rename each file according to their FileCreateDate so we can just sort by file name and be done with it
exiftool '-alldates=' '-FileName<${FileCreateDate}.%e' '-Directory=~/Downloads/sorted-rome-photos' ~/Downloads/rome-google-photos-download/*

Dev notes

All the possible incantations I tried around getting rid of all the extra date exif fields or aligning them to be the same without timezones, etc didn't work. Here is the scratch pad of some things tried in case you see something interesting to copy paste and reference.

exiftool '-CreateDate=' '-DateTimeOriginal='  '-FileCreateDate<FileCreateDate' '-FileModifyDate<FileModifyDate'  ~/Downloads/rome-google-photos-download/IMG_8140.heic


exiftool '-CreateDate=' '-DateTimeOriginal='  '-FileCreateDate<FileCreateDate' '-FileModifyDate<FileModifyDate' '-OffsetTime=' '-OffsetTimeOriginal=' '-OffsetTimeDigitized='  ~/Downloads/rome-google-photos-download/IMG_8140.heic


exiftool '-alldates=' '-FileCreateDate<FileCreateDate' '-FileModifyDate<FileModifyDate' ~/Downloads/rome-google-photos-download/IMG_8140.heic


exiftool '-CreateDate=' '-DateCreated=' '-DateCreated=' '-TimeCreated=' '-DateTimeDigitized=' '-DateTimeOriginal=' '-FileCreateDate<FileCreateDate' '-FileModifyDate<FileModifyDate' '-OffsetTime=' '-OffsetTimeOriginal=' '-OffsetTimeDigitized='  ~/Downloads/rome-google-photos-download/IMG_8140.heic

exiftool '-CreateDate<FileCreateDate' '-DateCreated=' '-TimeCreated=' '-DateTimeDigitized=' '-DateTimeOriginal=' '-FileCreateDate<FileCreateDate' '-FileModifyDate<FileModifyDate' '-OffsetTime=' '-OffsetTimeOriginal=' '-OffsetTimeDigitized='  ~/Downloads/rome-google-photos-download/IMG_8140.heic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment