Okay, so there are lots of reasons why I love Perl. I'm just going to tell you about the most recent one. If you haven't noticed already, I tend to be a bit of a shutterbug sometimes. I love taking pictures. I take pictures of my food on a regular basis, I take pictures at the Utah Bakers Dozen meetings, sometimes I even take pictures of just random objects.
This Monday was the most recent Utah Bakers Dozen meeting, and I showed up with my camera. There were a variety of desserts there, most of which had recipes. Some people brought multiple copies of their recipes, some people brought only one. I was sure to grab a copy of each recipe that had multiple copies, and photograph the ones that only had one copy (isn't 5 megapixel great?). The next day I retyped all of the recipes (I haven't been able to find Linux drivers for my scanner yet) and posted them on the UBD site. I also snapped off about a hundred photos of food, some of which weren't all that great. Having removed the photos I didn't want to show anyone, I still had about 60 photos, give or take. I wanted to post these on the UBD site (along with photos from past meetings), but there was going to be a lot of work involved.
I wanted to attach a UBD logo in the corner, just like I do with the images in my wallpaper area. I also wanted to make three different resolutions available, plus the thumbnail. And then there was the problem of making index pages for everything. Now, I had been through several different web-based gallery programs, and none of them really impressed me. Most were overly complex for what I wanted to accomplish, and still didn't offer all of the options that I actually wanted. The best one I found was Apache::Gallery, which Jayce uses on his site. I liked that it was written in Perl. I liked that it pretty much takes care of itself once you get it running. There were only a couple of problems with it. First of all, I didn't like having to disable DirectoryIndex. I don't use it at the moment, but I've used it several times in the past and I didn't want to limit myself. Plus, there was still the problem of the logo in the corner. Part of the reason I post photos is to provide content to keep people coming back to the site. Branding my photos would ensure that they knew where the photos came from, and hopefully encourage them to come back. And last, but not least, I couldn't get it working and I didn't want to spend the time fighting with it. I've found that when I start out fighting with a program, I tend to keep fighting with it until I give up and find something better.
Obviously, it was time to take matters into my own hands. I'd already used Image::Magick in the past, so I decided to use that. The idea was simple: write a script that takes each photo, stamps my logo in the corner and write out all the resolutions that I need. That didn't take long at all. But then it occurred to me that I would still have to create HTML indexes for the images. Why not have my script build a table for me? I could cut it where I needed to and then paste the tables into a pre-made template. Building the table was easy. And then I thought: wait a minute, why am I cutting up the table and pasting everything manually? It only took a few more simple steps to tell the script to create all the pages for me. Before long, I had the script pulling images from a source directory, writing new files to new destination directories, each numbered with the page of images that it held (/page1, /page2, etc). It was writing the index pages out with links to the other pages at the top and bottom of each page. It was doing all the work for me. Now I have a pretty nice-looking gallery of images from Monday's meeting posted.
Of course, there was a catch. All of my tweaking took time. In fact, I daresay it took about the same amount of time to write, debug and tweak my script as it would have to manually add my logo to each image, save out various resolutions and write the index pages. On the other hand, I didn't have to suffer through the tedium of doing all of that manually, and I got to give my brain a little excercise. Even better, when I process the next round of photos, it will only be a couple of minutes worth of actual work. With the first set of photos, I broke even on the time. But I have officially saved myself from hours of tedium and boredom that could be spent doing other things that I actually want to do, or at least should be doing.
There are a couple more things that I like about my little script. First of all, my little server isn't very powerful. I don't want images being generated on the fly, each time somebody wants to download something. In fact, I don't think I want a whole lot of pages generated on the fly. Text processing doesn't take up a lot of overhead. In fact, it generally takes almost none. But the more hits you get at a time, the more it takes. Static pages have less overhead than anything else, they're faster than anything else, and they're easier for search engines to index. Of course, that generally means more files to manage, but I'm willing to accept that for now. I'm dynamically generating the static pages anyway.
The script is admittedly still a bit rough. There's one minor bug that I know about, and several things that I would still like to make it do. Harley suggested that I release it to the public. Actually, he suggests I do that for pretty much everything I write. It's the whole open source thing, you know. Maybe I'll go ahead and release it when I have it a little more polished.
No comments:
Post a Comment
Comments for posts over 14 days are moderated
Note: Only a member of this blog may post a comment.