Raspberry Pi photo frame using your pictures on your Google Drive

Intro
All my spouse’s digital photo frames are either broken or nearly broken – probably she got them from garage sales. Regardless, they spend 99% of the the time black. Now, since I had bought that Raspberry Pi PiDisplay awhile back, and it is underutilized, and I know a thing or two about linux, I felt I could create a custom photo frame with things I already have lying around – a Raspberry Pi 3, a PiDisplay, and my personal Google Drive. We make a point to copy all our cameras’ pictures onto the Google Drive, which we do the old-fashioned, by-hand way. After 17 years of digital photos we have about 40,000 of them, over 200 GB.

So I also felt obliged to create features you will never have in a commercial product, to make the effort worthwhile. I thought, what about randomly picking a few for display from amongst all the pictures, displaying that subset for a few days, and then moving on to a new randomly selected sample of images, etc? That should produce a nice review of all of them over time, eventually. You need an approach like that because you will never get to the end if you just try to display 40000 images in order!

Python rotate image script
This simple script rotates an image if the orientation isn’t right. This happens a lot for our pictures we store on our google drive. Modern cellphones hide all this from you.

import sys
# mostly from https://stackoverflow.com/questions/13872331/rotating-an-image-with-orientation-specified-in-exif-using-python-without-pil-in -
# DrJ 8/2019
from PIL import Image, ExifTags
 
# loop over all aarguments, which are the files to be examined for their orientation
for img in sys.argv[1:]:
  try:
    image=Image.open(img)
    for orientation in ExifTags.TAGS.keys():
        if ExifTags.TAGS[orientation]=='Orientation':
            break
    exif=dict(image._getexif().items())
 
    if exif[orientation] == 3:
        image=image.rotate(180, expand=True)
    elif exif[orientation] == 6:
        image=image.rotate(270, expand=True)
    elif exif[orientation] == 8:
        image=image.rotate(90, expand=True)
    image.save(filepath)
    image.close()
 
  except (AttributeError, KeyError, IndexError):
    # cases: image don't have getexif
    pass

The above script isn’t so great I think because it uses PIL library which does not preserve the EXIF meta informaation. Better is something like this:

import sys
import pyexiv2
 
image = pyexiv2.Image(sys.argv[1])
image.readMetadata()
 
image['Exif.Image.Orientation'] = 6
image.writeMetadata()

To be continued…

References and related
PiDisplay

This entry was posted in Network Technologies, Raspberry Pi and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *