more cowbell
 
 


graciously hosted by neverblock
http://www.neverblock.com/

blog.josephhall.com


Saturday, October 11, 2008

slideshow.pl

I know I haven't posted any recipes in a while. I'll try to soon. In the meantime, I just wanted to drop this piece of code out there, in case anyone was interested.

I taught class this week (and last) at on site locations where Internet access was nothing more than a dream. During lunch and before class this week, I played with a little code. Actually, most of this program was written on the flight back, and then polished a little this morning. Actually, to say polished is probably exaggerating. It's a work in progress. In fact, some of the code is a little ugly. But I don't intend it to stay that way. Unlike so many of my past employers, I do plan on taking a piece of code that works, and make it work well.

You'll notice that I do ugly things, like using backticks a lot to call external programs when I should be using CPAN modules. Like I said, I didn't have Internet access when I wrote most of this, and I didn't have PerlMagick installed. I just went with straight command-line Image Magick. I'm going to go with the same excuse for using wget instead of LWP. Plus, wget -x -nc did a lot of work for me. But that wouldn't be any excuse for being lazy later, so I'll get that taken care of in a bit.

Here's the basic idea. You create a file called playlist.txt, which contains a list of images on your hard drive, or alternately, a list of image URLs. If you give it an http or ftp URL, it will download the image to a local cache, and then display it using the local copy. When you display a local image, the Javascript grabs the size of the browser's viewable area and uses Image Magick to resize the image to fit. Currenly, it resizes everything to fit, and an extra small image may look extra crappy when resized.

Speaking of sizing, the program relies upon knowing the viewable area, and passes it along as a GET method. If you call it without passing through that data, it displays a refresh screen for just long enough to collect it, and then moves into the image view portion.

The image viewer has links for the first, next, previous (prev) and last images. The playlist is pulled into an array, and then the program uses the pos variable as a cursor. This is ugly and hackish. I think that once I get all the backticks out of my code, yanking out the playlist mechanism and putting in something decent (preferably database-based) is probably next on the to-do list.

This program requires a web server. Since the web server writes to both the directory that the script sits in and the sites/ directory, they should both be owned by Apache's group, and set as chmod g+ws. To deal with browser cachine issues, the viewable image is always named using a timestamp. The program likes to clean up after itself, but since it doesn't do any sort of user or session tracking, it's really not suitable for multiple concurrent users.

Really, what it comes down to is, this is a really barebones script just waiting for you to customize and do all sorts of nifty things to. But it's kind of like buying a frozen pizza. You could just unwrap it and chow down, but sooner or later you'll be wishing you'd done something to it first, like maybe heat it up in the oven.

In fact, just one more warning, for those of you who didn't get it: do not install this on a publicly-available web server.

Here it is. Clicky!

0 Comments:

Post a Comment

<< Home