#!/usr/bin/perl -w use strict; if ($#ARGV != 0) { print STDERR "usage: $0 directory\n"; exit(2); } my $directory = shift @ARGV; $directory =~ s?/$??; my $file = 'captions.txt'; my $thumb_dir = 'thumbs'; my $medium_dir = 'medium'; my $large_dir = 'large'; my $top_page = "../index.html"; my $file_sep = '======'; my $tmp_sep = $/; my (@images, %image_info, $title, $date, $main_blurb, $photo_credit, $cover_image); # - Get the captions file, or make one up if none. if (not open (FILE, "$directory/$file")) { my @images_raw = split(/\n/, `file *`); my @images; foreach my $f (@images_raw) { my ($fname, $desc) = split(/:/, $f); if ($desc =~ /image data/) { push (@images, $fname); } } # We're just going to assume that there's no large/ dir here, rather # than be flexible and tolerate absence of captions.txt with # presence of large/. if (not -d $large_dir) { system("mkdir $large_dir"); foreach my $image (@images) { system("mv $image $large_dir"); } } open (FILE, ">$directory/$file") or die "unable to open $directory/$file for writing:$!"; print FILE "Photographs.\n"; print FILE "(captions generated automatically from filenames)\n"; print FILE $images[0] . "\n"; print FILE "\n"; print FILE "(no humans were involved in the making of this page)\n"; print FILE "\n"; print FILE "======\n"; print FILE "(no animals were harmed in the making of this page)\n"; foreach my $image (@images) { print FILE "======\n$image\n$image\n"; } close(FILE); open (FILE, "$directory/$file") or die "unable to open $directory/$file for reading:$!"; } system("mkdir $thumb_dir"); system("mkdir $medium_dir"); # - read the first bits off $title = ; $title =~ s/\s*$//; $date = ; $date =~ s/\s*$//; $cover_image = ; $cover_image =~ s/\s*$//; $/ = $file_sep; $main_blurb = ; $main_blurb =~ s/$file_sep//; $main_blurb =~ s/\s*$//; $photo_credit = ; $photo_credit =~ s/$file_sep//; $photo_credit =~ s/\s*$//; # print "TITLE:\n$title\n"; # print "DATE:\n$date\n"; # print "BLURB:\n$main_blurb\n"; ########################################################################### my $html_head = < $title, $date EOT my $html_foot = < EOT ########################################################################### # then stuff everything else into a hash. while () { $_ =~ s/$file_sep//; $_ =~ s/\s*$//; $_ =~ s/^\s*//; my ($filename, $caption) = split (/\n/, $_, 2); print "Processing: $filename\n"; # Check for existence of destination file, then if it's not there, create it. if (!-f "$medium_dir/$filename") { my $size = (-s "$large_dir/$filename"); # print "file size is $size\n"; if ($size > 250000) { system("convert -geometry 35% $large_dir/$filename $medium_dir/$filename"); } elsif ($size > 100000) { system("convert -geometry 50% $large_dir/$filename $medium_dir/$filename"); } else { system("convert -geometry 65% $large_dir/$filename $medium_dir/$filename"); } system("convert -geometry 15% $large_dir/$filename $thumb_dir/$filename"); } # print "CAPTION:\n$caption\n"; push(@images, $filename); $image_info{$filename} = $caption; } $/ = $tmp_sep; &create_thumb_page(); &create_medium_pages(); &create_index_page(); print "Done.\n"; ########################################################################### sub create_index_page(){ my $help = &thumbnailer_help(); my $first_page = $images[0]; $first_page =~ s/.jpg$/.html/; $first_page =~ s/.gif$/.html/; $first_page =~ s/.JPG$/.html/; $first_page =~ s/.GIF$/.html/; open (OUT, ">$directory/index.html") or die "Could not write to file $directory/index.html:$!"; print OUT <

$title

$cover_image

$date

$main_blurb

$photo_credit

$help EOT print OUT "

"; print OUT $html_foot; close (OUT); } ########################################################################### sub create_medium_pages() { my $index = 0; foreach my $filename (@images) { my $caption = $image_info{$filename}; my $html_filename = $filename; $html_filename =~ s/.jpg$/.html/; $html_filename =~ s/.gif$/.html/; $html_filename =~ s/.JPG$/.html/; $html_filename =~ s/.GIF$/.html/; #print "Writing file: $directory/$html_filename\n"; my $navigation = &previous_link($index) . &index_link() . &thumb_link() . &next_link($index); open (OUT, ">$directory/$html_filename") or die "Could not write to file $directory/$html_filename:$!"; print OUT < $navigation

$caption

$filename
$html_foot EOT close (OUT); $index++; } } ########################################################################### ########################################################################### sub create_thumb_page(){ # Create thumbnails page open (OUT, ">$directory/thumbnails.html") or die "Could not write to file $directory/thumbnails.html:$!"; print OUT $html_head; print OUT < Index

$title

EOT my $index = 1; foreach my $filename (@images) { my $html_filename = $filename; $html_filename =~ s/.jpg$/.html/; $html_filename =~ s/.gif$/.html/; $html_filename =~ s/.JPG$/.html/; $html_filename =~ s/.GIF$/.html/; my $short_caption = $image_info{$filename}; if (length($short_caption) > 25) { $short_caption = substr $short_caption, 0, 25; $short_caption =~ s/\w*$//; $short_caption =~ s/\s*$//; $short_caption .= "..."; } print OUT <
$filename

$short_caption EOT if ($index % 3 == 0) { print OUT " \n\n \n"; } $index++; } print OUT "
"; print OUT $html_foot; close (OUT); } ########################################################################### sub previous_link() { my $index = shift @_; if ($index == 0) { return ""; } my $html_filename = $images[$index - 1]; $html_filename =~ s/.jpg$/.html/; $html_filename =~ s/.gif$/.html/; $html_filename =~ s/.JPG$/.html/; $html_filename =~ s/.GIF$/.html/; return "<-- Previous "; } sub next_link() { my $index = shift @_; my $array_length = $#images; if ($index == $array_length) { return ""; } my $html_filename = $images[$index + 1]; $html_filename =~ s/.jpg$/.html/; $html_filename =~ s/.gif$/.html/; $html_filename =~ s/.JPG$/.html/; $html_filename =~ s/.GIF$/.html/; return "Next -->"; } sub index_link() { return " | Index"; } sub thumb_link() { return " | Thumbnails | "; } sub thumbnailer_help() { return <

-- Help --

In this photo catalog, there are three sizes of images: small, medium, and large. You can click on any small or medium size image to view the next larger size.

In addition to the small images, the thumbnails page contains a short preview of the image's caption. The medium-sized image page also contains the full caption for each image.

While not suitable for viewing on your computer screen (unless you have an 83 inch screen), "large" images are made available to allow you to create high-resolution prints from these images on your color printer.

This image catalog was created using software written by Brian Fitzpatrick

EOT }