This is the archive site for the pioneering blog CamWorld.com, which is no longer maintained.
Cameron Barrett's personal site can now be found at cameron.barrett.org and his professional site can be found at cameronbarrett.com.

May 14, 2003

Random Image + Metadata

I'm currently trying to figure out a way to randomly display an image from my extensive collection of digital photography, but I want to do more than just pick a random image from a directory and display it. That's what Hiveware's Image Rotator does with PHP and also what this Random Image Displayer script does in Perl.

What I want is a little script that can pull both an image plus some stored metadata (see left column), and display it randomly. I've looked at Menalto Gallery, but it seems like ovekill for what I want. Does anyone have pointers to a script (in PHP or Perl) that does what I need? The metadata would likely be stored in a MySQL table or even in a flat file.

Update: I found this recent tutorial on how to integrate Gallery into MovableType. Very interesting. I'm going to have to rethink my requirements.

Posted by Cameron Barrett at May 14, 2003 12:39 PM
Comments

If you're interested in rolling your own, this tutorial is pretty easy. You'd just have to add a row for your metadata.

http://www.phpdeveloper.org/view_tut.php?id=38


Posted by: Jeff Bunch at May 14, 2003 02:06 PM

This seems like a rather easy script to code, yes? Off the top of my head and untested, assuming a pipe-delimited file of image_name, title, year, comments:

#!/usr/bin/perl
use warnings;
use strict;

# open and slurp file.
open(FILE, "</path/to/file") or die $!;
my @records = <FILE>; close(FILE);

# get random entry.
my $rand = rand( scalar @records );

# now, split the entry.
my ($image, $title, $year, $comments)
= split(/\|/, $records[$rand]);

print "your html code here";
print "href = $image, alt = $title, etc.";

exit;

You could either run this through cron hourly, or every page load. Lemme know if it doesn't work, or if you need more help (CC me through email, if possible).


Posted by: Morbus Iff at May 14, 2003 04:59 PM

Nice to see you back, Cam. I am, however, surprised that you are not using a liquid layout. (I have a 1280x1024 monitor setting but keep my windows at 800 px wide, so the content column doesn't fit.)


Posted by: JD at May 14, 2003 11:13 PM

I've always been concerned about Gallery and the fact that it doesn't create search engine friendly URLs (see my matching tutorial below). Cam, any thoughts on this? As much as it looks good, I get a heavy portion of hits to my disobey.com/horror/ from Google Images, and I fear those'll disappear.

http://evolt.org/article/x/20/15882/


Posted by: Morbus Iff at May 15, 2003 09:04 AM

I use a gallery manager that I put together a while back using perl and XML here: http://www.majcher.com/xhibition/ - the code for the current release should be linked at the bottom of the page. It's a little assy right now, but you could make it do exactly what you want with the random images in about five lines, I think.

(After looking at the code again: I really need to get back to work on cleaning that up. It's a little embarrassing...)


Posted by: Marc Majcher at May 16, 2003 10:32 PM