hacker has asked for the wisdom of the Perl Monks concerning the following question:

I again approach the wisdom of the monks, not with a brain-twisting code example, but with a design query for assistance:

I have a proposed section of a new website I'm designing that was originally called "Screenshots", bland. I'm going to update this for the new site launch to be more of a "gallery" of images for users to walk through.

My question though, is: What is the best approach to tracking the image filename, alt tag, title tag, and a textual blurb that describes what is shown in the actual image itself?

I could use something like this (vars shortened here for space):

# t = TITLE tag # p = param passed # a = ALT tag # d = Description @img_list= ({t=>'palm', p=>'palm', a=>'Plucker running on the Palm', d=>'Plucker on the Palm device supports B&W, color, VFS, and external storage'}, # Handera in Scale-to-Fit (StF) mode {t=>'handera_stf', p=>'handera_stf', a=>'Plucker in Scale-to-Fit mode on the Handera'}, # HiRes Sony {t=>'sony_hr', p=>'sony_jd', a=>'Plucker on the Sony device in HiRes mode'}, # Sony with JodDial support {t=>'sony_jd', p=>'sony_jd', a=>'Plucker on the Sony device in HiRes mode'}, {...}, );

In this example, I could then display each image something like:

$last_img = pop @img_list; for my $item (@img_list) { print span({-class=>'mitem'}), a ({-href=>"$script?action=$item->{p}", -title=>"$item->{a}"}, img({-src=>"i/$item->{p}.gif", -border=>'0', -alt=>"($item->{a})"}), " $item->{t} " ), " | ", "\n"; }

This seems inefficient, and the hash gets uglier and larger as I add more images and more descriptive text to each one. Also, it doesn't allow one to click on one image and expand that into a page of several images (all "Palm" images for example, or all "Sony" images).

I'm wondering if there are other similar/better or different ways of thinking about doing this. I'm already using SQL (mysql) to hold the News articles on the site, so I could probably make a table there to hold the images and image data, but I've never personally done that, and then I have to deal with filesystem-based storage vs. storing the images in the database itself as a BLOB.

Has anyone done this? Any gotchas here? I can implement the perl bits.. I just can't wrap my head around the right design considerations with this approach yet.

Replies are listed 'Best First'.
Re: Image "gallery" design considerations
by janx (Monk) on Jun 19, 2002 at 12:01 UTC
    I'm wondering if there are other similar/better or different ways of thinking about doing this. I'm already using SQL (mysql) to hold the News articles on the site, so I could probably make a table there to hold the images and image data, but I've never personally done that, and then I have to deal with filesystem-based storage vs. storing the images in the database itself as a BLOB.

    IMHO you don't want to store the images as BLOB in the database.
    What we do here requires us to deal with quite a lot of images.
    We even have a separate cluster of machines just dealing with storing and delivering images.

    What I would suggest is:

    1. Store you pictures in the filesystem.
    2. Store the description, title, alt tag, keywords (very important), id etc. in the database.
    3. Figure out a way to map the database entry to the actual image file.
    We use a generated number as the filename which we store alongside with the vehicle information. But you also could just store the filename with the description in the database, so that you can freely choose your filenames.

    Another tip: Think about using templates. A great module would be HTML::Template by Sam Tregar.

    Kay

Re: Image "gallery" design considerations
by Chmrr (Vicar) on Jun 19, 2002 at 11:48 UTC

    It sounds like a database would be perfect for this job. Particularly because you seem to want to be able to look at the data from several viewpoints at once -- all "Palm" images, say, or all images one at a time in order, or ... This is the bread and butter of relational databases.

    You probably only want to store the textual data in the database. Generally, it's best to leave the files themselves to what deals with them best -- namely, the filesystem. It's more complicated, with far more overhead and possible pitfalls, and very little (if any!) gain, to put the images themselves into the database. It's oh-so much easier to just have a column for "image_url" which one can just spit out, and let the browser handle fetching the image from the webserver.

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Re: Image "gallery" design considerations
by caedes (Pilgrim) on Jun 19, 2002 at 12:30 UTC
    On my site (blatent self-promotion) I basically do exactly what was previously described and it has been working great for years. The image information in the database includes an unlimited number of keywords per image so that images can appear in any gallery that they seem to fit in. I generally only store very small images as BLOB (like link buttons, only a few kilobytes), so these images are stored on the filesystem. The database also makes it very easy to store the viewing statistics for each image so I can make neat tables like this. Let me know if you want any more info. :-)