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 which 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.
You will also find GPS location and IPTC data which contains information and the copyright of an image and keywords added in applications like Adobe Lightroom after the shot.
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.
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.
An upcoming update to the Pi3D image viewer software (the one that creates these beautiful image transitions) later in 2019, will have the possibility to filter your images on specific dates or date ranges, 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 which 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.
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 "check_exif_date.py" with the code below.
Enter your Pictures directory in line 48. Pay attention for capital and small letters as this needs to be correct.
Script for scanning JPG's with invalid DATE in Exif
Prerequisite: pip3 install exifread
#scan if current directory is accessible or not
#permission denied removal
CurrentDirectoryFiles = os.listdir(dirName)
#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
#otherwise check if jpg and has valid exif date
if (filePath.endswith(".jpg") or filePath.endswith(".jpeg")) and not (entry.startswith(".")) and not ".AppleDouble" in filePath:
f = open(filePath, 'rb')
tags = exifread.process_file(f)
#check if DATE exist in EXIF if not then print that file path
print("-------------------Invalid Valid Exif Date Finder-----------------------")
directoryStarting = "/home/pi/Pictures/your_photos/"
print("Directory Selected is :", directoryStarting)
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
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.
However, this is just the beginning of an upcoming Pi3D image viewer release.
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 be able one day to voice control 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.