March 07, 2006

Picture Pages, Picture Pages

Once I got the Audrey up and running, one of the first projects I attempted was a digital picture frame. Since the Audrey is pretty small, is in plain view in the kitchen, and is pretty much always on, I figured it would be perfect for such an application.

Turns out there are a couple ways to do this, all of which are pretty complicated. But seeing as how the Audrey has a great full-screen web browser, and I'm a web guy more than a Unix guy, I decided to just have Audrey display the photos as a web-page.

To do so, I set up an Apache webserver on my computer that has all the photos on it. Then I wrote a script (in PHP), which will pick a photo at random, resize it to fit on Audrey's screen, and then serve it on the page. Then I set up an Audrey channel to point to the URL of this PHP script.

This worked great, but it was pretty slow, since I have a lot of photos, so picking one takes a while. Also, resizing the photo takes a second or two. So I made two improvements to the script to improve the speed. First, I switched the order of operations: Now, I show a photo, and then pick a photo at random and resize it to be served the next time the script is called. This way, the parts of the script that are time-intensive are run after a photo has already been shown. Second, I decided to cache the list of photos on my computer, so that the script doesn't have to re-read all the photos on my computer on each load. I save the cache to a file, and the next time the script loads, it reads from the cache file. If the cache file is more than a day old, I build a new cache file, to make sure I have the most recent photos.

If you're interested, here's the final code for it:
Main PHP script
Library to resize image

Posted by Kevin at March 7, 2006 04:04 PM