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!

This is more relevant now than when I wrote it, not less. picframe3 filters by date — including rolling windows like the last 30 days and on this day, which re-resolve themselves as the days pass — and by tag and by place, all of it read out of your files’ metadata. A photograph with no Exif date simply never appears in any of those selections. The script below tells you which ones those are.

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. On a Pi 4 or Pi 5, its successor picframe3 does the same and more — folder, tags, place, an explicit date range or a rolling window, with a live count of how many photographs a filter selects before you apply it.

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.

Set your Pictures directory in the directoryStarting line near the bottom of the script. 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 = os.path.expanduser("~/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. I used to write that path as /home/pi/…; Raspberry Pi OS no longer creates a default pi account, so ~ is the spelling that is right on every frame.

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

Since Bookworm, Raspberry Pi OS refuses a system-wide pip install — you get error: externally-managed-environment. The article used to say pip3 install exifread, which no longer works. Make a small virtual environment for it instead:

python3 -m venv ~/venv_exif
~/venv_exif/bin/pip install exifread

and run the script with that Python:

~/venv_exif/bin/python3 exif_date_check.py

If you would rather not bother with a virtual environment, sudo apt install python3-exifread may have it packaged, in which case a plain python3 exif_date_check.py works.

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 pi3d PictureFrame on an older Pi, or with picframe3 on a Pi 4 or Pi 5.

Two notes if you are on picframe3. It has a picframe3 doctor command that checks the frame itself — hardware, drivers, permissions, library — and prints the fix for whatever it finds; it is worth running before you go hunting for problems in your files. And picframe3 indexes more than JPGs: PNG, HEIC and video are all in the library. The script below only looks at .jpg and .jpeg, so it will not tell you anything about those. Add the extensions you care about to the filePath.endswith check if you want the full picture.

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.