Replacing Exif data with Python
A while back I had the sensibility to download all my pictures off Facebook to a local folder. In fact, I wrote a Chrome extension to do that because I couldn’t find that functionality in Facebook’s farcical interface. I’m kind of surprised I never hit a Facebook spamfilter while downloading a solid 550 pictures through essentially a bot-extension, but I guess they were too busy finding alternative ways to give Cambridge Analytica access to all their data back then.
Most of those pictures had gotten stripped of all their Exif data along the way. I had been smart enough to extract the upload date of the picture, and name the file after it, but Synology Moments doesn’t use the name of the file to set its date. It parses the Exif data only, and if that doesn’t exist, it will just use the day the files were created. Result: I had 550 pictures taken on a rainy October day in 2016. That can’t be right.
Scripting it up
As luck would have it, all of these images got uploaded to the same directory in the
~/Drive/Moments/Drive/2016-10-05/ folder on my Synology. That means I had to do three things:
- Mount the Synology directory over NFS on my laptop
- Slap together a Python script that parses filenames to a date and writes it to the Exif data
- Run it on the mounted directory
I won’t go through the details of mounting an NFS drive. Actually, I’m not going to go through the details of the rest either, you should be able to figure that out. The long and short of it: my function relies on
PIL. The rest should be self-explanatory: loop through the files in the directory and call the function. This is all in
python3 though I’m fairly certain it would work with minor adjustments in
python2 as well.