Sleepy Weim

ActionTiles: Picture Tiles that Change

One of the big things I was excited to do with ActionTiles was display photos. I have a huge folder of thousands of pictures organized on my local Synology that I also sync to Google Drive. Unfortunately, the options for trying to show rotating photos in ActionTiles was lacking (no offense guys!).

After playing around with ActionTiles itself for a bit, I realized I could have a Media Tile with a URL that points at a static web location, and then could write a script that would periodically change that file. By doing that, the standard Media Tile to load a graphic or GIF could do it’s thing, and I’d do the heavy lifting on the back end.

It was a little more complicated than I expected.

Writing a script to load a list of pictures and then just save it to a location with a set filename was my goal, and wasn’t terrible. It’s actually how I initially hit upon the python/Synology setup I’m currently using. However, there were many issues I ran into that I wanted to address:

  • All my tiles are landscape; of course many of my photos are portrait
  • I have all these other MOV files mixed in too, so I need to ignore those
  • What happens if I don’t find a good file in a directory?
  • What happens if there are hundreds of bad files in a single directory?
  • Why are these damn photos displaying the wrong way? Why didn’t my script see they weren’t landscape?

Landscape vs. Portrait

This was where I started. I have several tiles that are in a 2×3 tile configuration, so landscape will look just fine. You may choose to have only portrait tiles, or maybe you want a mix of both. In the script I have a simple if..then.. statement that extracts the height and width data, then does a comparison. If the width is more than the height, then it’s landscape, otherwise portrait.

…Unless the EXIF says otherwise

Photo files generally have EXIF data. EXIF data stores a wide array of things that I don’t care about. But I ran into the issue that I would clearly see that a photo _should be_ landscape, but when the photo loaded in AT it was sideways or even upside down.

Checking the photo on my laptop, the photo would load correctly, and normally in portrait mode. So what is going on? When the photo was taken, someone held the camera sideways or upside down. The camera records that information in the EXIF data, and then the viewer you use must know what to do with it.

In my case, ActionTiles and Firefox seemed to be happy ignoring it. I added a function in the script that therefore reads the EXIF data, determines if the file was rotated, and then rotates the image itself so it loads correctly.

JPG, and JPEG, and PNG oh my!

Don’t judge. I’m trying at least.

While most of my folders are well organized, sometimes random files do end up in there, or with all the live photos phones take, there are often movie files mixed in. In short, we look at the file extension to determine what we want to inspect and which we want to ignore. You can easily adjust this for other file formats you may want to use.

We also do an inspection for directories. If we find that our random selection is in fact a directory, we then navigate into that folder, and start the process again. That way we can have a parent folder, for example ‘Running’, and then have our photos organized in subfolders that the script with navigate. It helps avoid having to rework a folder just for the script, and lets you keep your photos organized.

No Good Files

It’s often possible that no good picture file is found. For example, I have some folders where I put all the movie files, or that day we only took pictures in a portrait orientation, or there are hundreds of non-picture files because someone put a bad folder in the photo directory.

Some of these I address nicely, and some are a bit more ugly.

First, the script runs in a basic FOR loop that will run 200 times. This is just so that the script doesn’t get stuck and run forever. That’s all. I found 100 seemed too short for a couple of my folders, and I load four different photo tiles right now, so I didn’t want it processing for any serious length of time.

If you get to the end of the folder and have found no good files, we step back up a folder directory and try again. This let’s us select a ‘bad’ folder first, run through until the end, and then step back out to try again. It’s not by any means perfect, but for loading pictures on a tablet in my kitchen it’s just fine.

v2 is going to be a little more intelligent about it. There is a chance you could navigate out of a bad folder, only to have the script randomly select the bad folder you were just in. For me this isn’t likely due to how many folders I have, but if you only have two or three, you chance is much higher.

Like I said, v2.

Anyways, on to the script.

Leave a Reply

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