Check the Exif data of your images to pre­pare your pho­to frame for smart playlists

-

Did you ever wish you could eas­i­ly fil­ter the images on your dig­i­tal pic­ture frame based on the date?

Maybe you just came back from hol­i­day, and you want to see pho­tos from the last three weeks.

Or it's your kid's tenth birth­day, and you only want to show images that were tak­en on his birth­day from every year.

The date infor­ma­tion is con­tained as Exif data in your JPG files. In this arti­cle, I will show you a Python 3 script which checks your pho­to library on your dig­i­tal pic­ture frame for Exif date com­plete­ness so that you are ready to use smart fil­ters!

The dig­i­tal foot­print in your pho­tos

Do you remem­ber those red date stamps that old­er cam­eras left on your image back in the ana­log days? I always felt like it ruined the pho­to, but I guess some mar­ket­ing peo­ple deemed the infor­ma­tion as use­ful.

For­tu­nate­ly, in the dig­i­tal days, this infor­ma­tion can be record­ed with­out the need to have it appear on the image.

When­ev­er you take a dig­i­tal pho­to, a set of data is being writ­ten along­side the image infor­ma­tion. This includes the Exif data, which records not only the date but also the ser­i­al num­bers of your cam­era body and lens­es, aper­ture and shut­ter speed, or your white bal­ance.

Excerpt of Exif data of a dig­i­tal pho­to

You will also find GPS loca­tion and IPTC data which con­tains infor­ma­tion and the copy­right of an image and key­words added in appli­ca­tions like Adobe Light­room after the shot.

IPTC date with key­words, author and loca­tion data

If you like to take a lot of images, this infor­ma­tion can be handy to find a par­tic­u­lar pho­to quick­ly.

But it can also be used to cre­ate smart playlists that fil­ter your images accord­ing to spe­cif­ic cri­te­ria.

Smart Playlists

For a dig­i­tal pic­ture frame, the most use­ful selec­tion is prob­a­bly on the date, peo­ple, loca­tion, and oth­er freely defined key­words.

The Exif infor­ma­tion is some­times removed from the file dur­ing pho­to manip­u­la­tion. Sav­ing an image with­out this data over­head will cre­ate an only slight­ly small­er file. But the dif­fer­ence is less than 1%, so there is no point in remov­ing this infor­ma­tion for your dig­i­tal pic­ture frame.

An upcom­ing update to the Pi3D image view­er soft­ware (the one that cre­ates these beau­ti­ful image tran­si­tions) lat­er in 2019, will have the pos­si­bil­i­ty to fil­ter your images on spe­cif­ic dates or date ranges, so basi­cal­ly cre­ate a smart playlist.

This is so much bet­ter than sta­t­ic playlists. While I under­stand the util­i­ty of a fixed playlist for com­mer­cial appli­ca­tions, I don't believe it makes much sense to have them for home use.

A pic­ture frame is meant for casu­al image view­ing, so typ­i­cal­ly you don't stand in front of the frame and watch ten pho­tos in a row. Instead, it's the sur­prise of what is shown next and the tran­si­tion effect of slow cross­fad­ing, which cre­ates sus­pense and fun.

Also, man­u­al playlists require con­stant main­te­nance, which you prob­a­bly don't want to under­take.

In a dynam­ic, or smart playlist, on the oth­er hand, you define spe­cif­ic cri­te­ria, and when­ev­er you add images that match them, your playlist is dynam­i­cal­ly updat­ed.

But for a smart playlist to work, your files must have this infor­ma­tion. So, for a quick test of the Exif qual­i­ty of your pho­to library on your dig­i­tal pic­ture frame, I have writ­ten a script which checks each of your files in all direc­to­ries if they have a valid Exif date.

In my case, I found that I had export­ed about 250 pho­tos from Adobe Light­room with­out meta­da­ta, and a smart fil­ter would have ignored them.

So before I could use the new func­tion­al­i­ty in the Pi3D script, I need­ed to make a new export. The Exif date check script sup­plied me with the file names of those images that would not work with my smart fil­ters which made the process quick and effort­less.

If you are using Adobe Light­room to devel­op your pho­tos, make sure that your export set­tings are spec­i­fied for full meta­da­ta export.

Make sure you have "All Meta­da­ta" select­ed in Lightroom's export set­tings

The Python 3 script to check for a valid Exif date in your pho­to files

Installing and run­ning this script is straight­for­ward.

Cre­ate a new file called "check_exif_date.py" with the code below.

Enter your Pic­tures direc­to­ry in line 48. Pay atten­tion for cap­i­tal and small let­ters as this needs to be cor­rect.

  1. #!/usr/bin/env python3
  2.  
  3. """
  4. Script for scanning JPG's with invalid DATE in Exif
  5. Prerequisite: pip3 install exifread
  6. """
  7.  
  8. import os
  9. import exifread
  10.  
  11. def ScanInvalidExifDate(dirName):
  12.  
  13.     try:
  14.         #scan if current directory is accessible or not
  15.         #permission denied removal
  16.         CurrentDirectoryFiles = os.listdir(dirName)
  17.     except:
  18.         return
  19.  
  20.     #iterate over results of current direcotry files
  21.     for entry in CurrentDirectoryFiles:
  22.  
  23.         #create a full file path with dir + file name
  24.         filePath = os.path.join(dirName, entry)
  25.  
  26.         #check if full file path is another directory then recursively operate
  27.         if os.path.isdir(filePath):
  28.             ScanInvalidExifDate(filePath)
  29.  
  30.         #otherwise check if jpg and has valid exif date
  31.         else:
  32.             if (filePath.endswith(".jpg") or filePath.endswith(".jpeg")) and not (entry.startswith(".")) and not ".AppleDouble" in filePath:
  33.                 filePath= '/'.join(filePath.split('\\'))
  34.                 f = open(filePath, 'rb')
  35.                 tags = exifread.process_file(f)
  36.                 f.close()
  37.  
  38.                 #check if DATE exist in EXIF if not then print that file path
  39.                 try:
  40.                     tags['EXIF DateTimeOriginal']
  41.                 except:
  42.                     print(filePath)
  43.     return
  44.  
  45. if __name__=="__main__":
  46.     print("-------------------Invalid Valid Exif Date Finder-----------------------")
  47.     while True:
  48.         directoryStarting = "/home/pi/Pictures/your_photos/"
  49.         if os.path.exists(directoryStarting):
  50.             print("Directory Selected is :", directoryStarting)
  51.             print("---------Scanning-------------")
  52.             ScanInvalidExifDate(directoryStarting)
  53.             break
  54.         else:
  55.             print("Invalid Directory Entered")

Put this file into the home direc­to­ry of your Rasp­berry Pi.

Before we can run this script, we must first install the exif­read pack­age.

In Ter­mi­nal enter

pip3 install exifread

To run the script enter

python3 exif_date_check.py

The out­put will be print­ed in the Ter­mi­nal win­dow, and you can fix those files in Adobe Light­room or what­ev­er image manip­u­la­tion soft­ware you are using.

pi@pictureframe:~ $ python3 exif_date_check.py
-------------------Invalid Valid EXIF DATE Finder-----------------------
Directory Selected is : /home/pi/Pictures/Photos/
---------Scanning-------------
/home/pi/Pictures/Photos/2013/2013 Scotland/13W_6753.jpg
/home/pi/Pictures/Photos/2008/2008 South Africa/2008 South Africa - 0888.jpg
/home/pi/Pictures/Photos/2008/2008 South Africa/2008 South Africa - 1577.jpg
/home/pi/Pictures/Photos/2008/2008 South Africa/2008 South Africa - 0981.jpg
/home/pi/Pictures/Photos/2008/2008 South Africa/2008 South Africa - 1632.jpg

More to come

This script lets you check the Exif com­plete­ness of your pho­to library. This is impor­tant if you ever want to use smart playlists based on dates.

How­ev­er, this is just the begin­ning of an upcom­ing Pi3D image view­er release.

The ambi­tion is to add fil­ter­ing on IPTC data, which will include loca­tions, peo­ple, and any key­words of your choos­ing.

And then one day, you may be able one day to voice con­trol smart playlists with Alexa or Google Home.

But tidy­ing up your image library is the first step, and this is where our lit­tle script can pro­vide use­ful sup­port.