#!/usr/bin/perl # Displays a photo gallery of all jpg files in the thumbnails directory # Assumes existence of identically named full-sized files in base directory use strict; use CGI; use vars qw( $PICS_PER_PAGE $PICS_PER_ROW $GALLERY_HTML ); $PICS_PER_PAGE = 24; $PICS_PER_ROW = 6; $GALLERY_HTML = < Photography by Jack Ditch

Head In The Clouds
Photography by Jack Ditch

Folks have always told me that I've got my head in the clouds, and I guess it's true. As soon as I got a digital camera for Christmas, I couldn't stop looking up for pictures to snap. Here are my best results from the first couple months. Picture timestamps are unreliable, but know that the pictures are in chronological order, starting on December 27 2006 and ending on February 23 2007. Love and gratitude to Mom & Dad for the camera!

PLACE_NAVBAR_HERE PLACE_PHOTOROWS_HERE
-><- EOF print "Content-type: text/html\n\n"; my @thumbs; opendir(THUMBS,"thumbnails"); foreach my $thumb (readdir THUMBS) { push(@thumbs,$thumb) if $thumb =~ /\.jpg/; } closedir THUMBS; my $photocount = $#thumbs + 1; my $pagecount = $photocount / $PICS_PER_PAGE; my $cgi = CGI->new(); my $page = $cgi->param('page') || 1; if (($page !~ /^\d+$/) or ($page - $pagecount >= 1)) { print "Invalid page number $page"; die "Invalid page number $page"; } my $lastpage = $page - 1; my $nextpage = ($pagecount - $page > 0) ? $page + 1 : 0; my $firstphoto = $lastpage * $PICS_PER_PAGE; my $lastphoto = $firstphoto + $PICS_PER_PAGE - 1; $lastphoto = ($lastphoto > ($photocount - 1)) ? $photocount - 1 : $lastphoto; my $out = $GALLERY_HTML; my $navbar = ''; $navbar .= qq() if $lastpage; $navbar .= qq(<<Prev); $navbar .= qq() if $lastpage; my $pageiterate = 1; while ($pageiterate - $pagecount < 1) { $navbar .= " "; $navbar .= qq() unless ($pageiterate == $page); $navbar .= $pageiterate; $navbar .= qq() unless ($pageiterate == $page); $pageiterate++; } $navbar .= " "; $navbar .= qq() if $nextpage; $navbar .= qq(Next>>); $navbar .= qq() if $nextpage; $out =~ s/PLACE_NAVBAR_HERE/$navbar/; my $photoiterate = $firstphoto; my $rowcount = 0; my $rowtext = ''; while ($photoiterate <= $lastphoto) { my $photoname = $thumbs[$photoiterate]; $rowcount++; $rowtext .= qq(\n) if ($rowcount == 1); $rowtext .= qq(\n); $rowtext .= qq(\n) if ($rowcount == $PICS_PER_ROW); $rowcount = 0 if ($rowcount == $PICS_PER_ROW); $photoiterate++; } $out =~ s/PLACE_PHOTOROWS_HERE/$rowtext/; print $out; 1; __END__