Avleen
Avleen

Reputation: 252

Adding exif dates and times to images

I have a few hundred photos which are missing the correct createdate field. I need this so that when I upload them to Google Photos, they'll be sorted correctly.

Fortunately almost all of the photos have another date field which is correct, either datetimeoriginal or modifydate or something.

I was hoping to use the python exif module to scan the files, find the date field with the oldest time and use that to add the createdate field. Unfortunately that module doesn't seem to like adding new exif fields where they don't already exist. It errors out with:

RuntimeError: only can add GPS IFD to image, not exif

What other options do I have for adding the missing fields? Preferably using Python, but Ruby or Go would be OK too :-)

Upvotes: 1

Views: 1382

Answers (1)

olha
olha

Reputation: 2262

You definitely should look at ExifTool command-line util. It's quite powerful, so probably it's possible not to write script at all.

Even if it would be hard to batch-process your task, you could call exiftool from Python with subprocess module ( subprocess.call(["exitfool", "param1", "param2"])/subprocess.check_output(["exitfool", "param1", "param2"])).

Here's my attempt to approach your problem (command-line):

We have a photo test.HEIC. Let's look at its date-related EXIF:

Olhas-MBP:Downloads olia$ exiftool test.HEIC  | grep Date

File Modification Date/Time     : 2020:07:19 21:41:19+03:00
File Access Date/Time           : 2020:07:19 21:41:19+03:00
File Inode Change Date/Time     : 2020:07:19 21:41:19+03:00
Modify Date                     : 2020:03:30 11:41:02
Date/Time Original              : 2020:03:30 11:41:02
Create Date                     : 2020:03:30 11:41:02
Profile Date Time               : 2017:07:07 13:22:32
Create Date                     : 2020:03:30 11:41:02.891+03:00
Date/Time Original              : 2020:03:30 11:41:02.891+03:00
Modify Date                     : 2020:03:30 11:41:02+03:00

So, this photo has both Create Date and Modify Date. Let's set "Create Date" to now:

exiftool -r -all= -createdate=now "-exif:createdate<createdate" -overwrite_original test.HEIC
    1 image files updated

Now, let's see the updated tags:

Olhas-MBP:Downloads olia$ exiftool test.HEIC | grep Date
File Modification Date/Time     : 2020:07:19 21:51:52+03:00
File Access Date/Time           : 2020:07:19 21:51:53+03:00
File Inode Change Date/Time     : 2020:07:19 21:51:52+03:00
Create Date                     : 2020:07:19 21:51:52+03:00
Profile Date Time               : 2017:07:07 13:22:32

Now, let's set "Create Date" to "Modify Date" (not sure if I chose the correct tags actually):

Olhas-MBP:Downloads olia$ exiftool -r -all= -createdate=now "-FileModifyDate<FileCreateDate" -overwrite_original test.HEIC
    1 image files updated

Olhas-MBP:Downloads olia$ exiftool test.HEIC | grep Date
File Modification Date/Time     : 2020:07:19 21:53:19+03:00
File Access Date/Time           : 2020:07:19 21:54:09+03:00
File Inode Change Date/Time     : 2020:07:19 21:54:08+03:00
Create Date                     : 2020:07:19 21:54:08+03:00
Profile Date Time               : 2017:07:07 13:22:32

Olhas-MBP:Downloads olia$ exiftool -r -all= -createdate=now "-FileModifyDate<CreateDate" -overwrite_original test.HEIC
    1 image files updated

Olhas-MBP:Downloads olia$ exiftool test.HEIC | grep Date
File Modification Date/Time     : 2020:07:19 21:54:08+03:00
File Access Date/Time           : 2020:07:19 21:54:51+03:00
File Inode Change Date/Time     : 2020:07:19 21:54:50+03:00
Create Date                     : 2020:07:19 21:54:50+03:00
Profile Date Time               : 2017:07:07 13:22:32

Upvotes: 2

Related Questions