Did you ever wish you could easily filter the images on your digital picture frame based on the date?

Maybe you just came back from holiday, and you want to see photos from the last three weeks.

Or it’s your kid’s tenth birthday, and you only want to show images that were taken on his birthday from every year.

The date information is contained as Exif data in your JPG files. In this article, I will show you a Python 3 script that checks your photo library on your digital picture frame for Exif date completeness so that you are ready to use smart filters!

The digital footprint in your photos

Do you remember those red date stamps that older cameras left on your image back in the analog days? I always felt like it ruined the photo, but I guess some marketing people deemed the information as useful.

Fortunately, in the digital days, this information can be recorded without the need to have it appear on the image.

Whenever you take a digital photo, a set of data is being written alongside the image information. This includes the Exif data, which records not only the date but also the serial numbers of your camera body and lenses, aperture and shutter speed, or your white balance.

Excerpt of Exif data of a digital photo

You will also find GPS location and IPTC data which contain information and the copyright of an image and keywords added in applications like Adobe Lightroom after the shot.

IPTC data with keywords, author and location data

If you like to take a lot of images, this information can be handy to find a particular photo quickly.

But it can also be used to create smart playlists that filter your images according to specific criteria.

Smart Playlists

For a digital picture frame, the most useful selection is probably on the date, people, location, and other freely defined keywords.

The Exif information is sometimes removed from the file during photo manipulation. Saving an image without this data overhead will create an only slightly smaller file. But the difference is less than 1%, so there is no point in removing this information for your digital picture frame.

The Pi3D Picture Frame image viewer software (the one that creates these beautiful image transitions) has the possibility to filter your images on specific dates, date ranges, and many more metadata, so basically create a smart playlist.

This is so much better than static playlists. While I understand the utility of a fixed playlist for commercial applications, I don’t believe it makes much sense to have them for home use.

A picture frame is meant for casual image viewing, so typically, you don’t stand in front of the frame and watch ten photos in a row. Instead, it’s the surprise of what is shown next and the transition effect of slow crossfading, which creates suspense and fun.

Also, manual playlists require constant maintenance, which you probably don’t want to undertake.

In a dynamic, or smart playlist, on the other hand, you define specific criteria, and whenever you add images that match them, your playlist is dynamically updated.

But for a smart playlist to work, your files must have this information. So, for a quick test of the Exif quality of your photo library on your digital picture frame, I have written a script that checks each of your files in all directories if they have a valid Exif date.

In my case, I found that I had exported about 250 photos from Adobe Lightroom without metadata, and a smart filter would have ignored them.

So before I could use the new functionality in the Pi3D script, I needed to make a new export. The Exif date check script supplied me with the file names of those images that would not work with my smart filters, which made the process quick and effortless.

If you are using Adobe Lightroom to develop your photos, make sure that your export settings are specified for full metadata export.

Make sure you have “All Metadata” selected in Lightroom’s export settings

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

Installing and running this script is straightforward.

Create a new file called “exif_date_check.py” with the code below.

Enter your Pictures directory in line 48. Pay attention to capital and small letters, as this needs to be correct.

#!/usr/bin/env python3

"""
Script for scanning JPG's with invalid DATE in Exif
Prerequisite: pip3 install exifread
"""

import os
import exifread

def ScanInvalidExifDate(dirName):

    try:
        #scan if current directory is accessible or not
        #permission denied removal
        CurrentDirectoryFiles = os.listdir(dirName)
    except:
        return

    #iterate over results of current direcotry files
    for entry in CurrentDirectoryFiles:

        #create a full file path with dir + file name
        filePath = os.path.join(dirName, entry)

        #check if full file path is another directory then recursively operate
        if os.path.isdir(filePath):
            ScanInvalidExifDate(filePath)

        #otherwise check if jpg and has valid exif date
        else:
            if (filePath.endswith(".jpg") or filePath.endswith(".jpeg")) and not (entry.startswith(".")) and not ".AppleDouble" in filePath:
                filePath= '/'.join(filePath.split('\\'))
                f = open(filePath, 'rb')
                tags = exifread.process_file(f)
                f.close()

                #check if DATE exist in EXIF if not then print that file path
                try:
                    tags['EXIF DateTimeOriginal']
                except:
                    print(filePath)
    return

if __name__=="__main__":
    print("-------------------Invalid Valid Exif Date Finder-----------------------")
    while True:
        directoryStarting = "/home/pi/Pictures/your_photos/"
        if os.path.exists(directoryStarting):
            print("Directory Selected is :", directoryStarting)
            print("---------Scanning-------------")
            ScanInvalidExifDate(directoryStarting)
            break
        else:
            print("Invalid Directory Entered")

Put this file into the home directory of your Raspberry Pi.

Before we can run this script, we must first install the exifread package.

In Terminal enter

pip3 install exifread

To run the script enter

python3 exif_date_check.py

The output will be printed in the Terminal window, and you can fix those files in Adobe Lightroom or whatever image manipulation software 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 completeness of your photo library. This is important if you ever want to use smart playlists based on dates with software like Pi3D PictureFrame 2021.

The ambition is to add filtering on IPTC data, which will include locations, people, and any keywords of your choosing.

And then one day, you may want to set up voice-controlled smart playlists with Alexa or Google Home.

But tidying up your image library is the first step, and this is where our little script can provide useful support.