#!/usr/bin/perl # $Id: pmi2,v 1.1 2000/08/20 08:36:15 jzawodn Exp $ ### Modules use Cwd; use Image::Size 'html_imgsize'; use strict; ### Subs sub print_navbar; sub print_footer; sub gifn($); sub Log($); ### Globals my @filelist; ## Grab file listing... { if (not @ARGV) { opendir D, '.' or die "$!"; @filelist = grep { /\d+\.jpg/i } readdir D; closedir D; } } @filelist = sort @filelist; my $filename; my $basename; my $title; my $newtitle; my $description; my $filecount = scalar @filelist; my $pagesize = 4; my $indexcount = $filecount / $pagesize; my $pagecounter = 1; my $imagecounter= 1; my $timestamp = scalar(localtime(time)); my $indexfilename; my $comments; my %rotate; my $year = (localtime(time))[5] + 1900; my $dir = getcwd; Log("dir: $dir"); $dir =~ /(.*)\/(.+)$/; $dir = $2; Log("dir: $dir"); ### Main (this is one big, ugly script) # Is the "comments" flag on? If so, we'll generate "Comment" links on # all the pictures so that I can flag them and say something witty. if (-e "/tmp/comments") { $comments = 1; } else { $comments = 0; } # Open the log file. It's always log.txt in the current directory. open(LOG, ">log.txt") or die "$!"; # Figure out how many index pages we need. This is just an odd way of # rounding the fractional value up to the next whole number and then # stripping off the decimal stuff. if ($indexcount =~ /\./) { $indexcount++; $indexcount = sprintf("%d", $indexcount); } if ($indexcount > 1) { Log("We're in multi-file mode."); } else { Log("We're in single-file mode. Just like school."); } Log("Will make $indexcount index files for a $filecount images."); # Get Title from the title.txt file in the current directory. Titles # are only one line long. if (-e "title.txt") { open(TITLE, "; chomp $title; close(TITLE); Log("Got title."); } # Get Description from the description.txt in the current # directory. Descriptions can be as long as we want. if (-e "description.txt") { $description = ""; open(DESC, ") { $description .= $_; } close(DESC); $description = "

" . $description; $description =~ s/\n\n+/\n\n\\n/; $description .= "

"; Log("Got description."); } else { warn "No description exists.\n"; } # Read in the rotation file if it exists. if (-e "rotate.txt") { Log("Reading rotation file."); open(ROT, ") { chomp; my ($file,$direction) = split /\s+/, $_, 2; $rotate{$file} = $direction; Log("$file will rotate to the $direction"); } close(ROT); } ###################################### # # Here's the big loop for all files. # ###################################### my $imagecount = 0; my $ipagecount; FILELOOP: { Log("Entering top of loop."); # Determine filename if ($pagecounter == 1) { $indexfilename = "index.html"; } else { $indexfilename = "index-$pagecounter.html"; } # And the page numbering for the title/header $newtitle = $title . " (page $pagecounter of $indexcount)"; Log("Index name will be $indexfilename."); # Do the HTML crap for the header... open(HTML, ">$indexfilename") or die "Can't open indexfilename"; select(HTML); print< $newtitle

Jeremy's Home -> Picture Gallery -> $newtitle

$newtitle

Each picture is a small JPEG. They are meant to be thumbnail images. Click on any picture below to see a larger JPEG with better color. I have even larger ones available on request (roughly twice the size of the biggest ones I put on-line).

The Pictures

$description EOHEADER # Navbar at the top print_navbar; # Stick the graphics in... my $caption; my $filename; ############################################################ # # Here's the inner loop for each image on the current page. # ############################################################ # $imagecount is not initialized # $filecount is $#ARGV+1 # $ipagecount is not initialized # $pagesize is a constant print "\n
\n"; my $table_col_count = -1; while (($imagecount < $filecount) and ($ipagecount < $pagesize)) { $filename = $filelist[$imagecount]; #$filename = $filelist[$imagecount+1]; Log("File to link is $filename."); $filename =~ m/(.*)\..*/o; $basename = $1; # See if we need to rotate the file and use the rotated # version. # Grab the image caption (if exists). if (-e "$basename.txt") { open(CAP, "<$basename.txt") or die "$!"; $caption = ; chomp $caption; close(CAP); } else { $caption = ""; } # Get the image size my $imagesize = html_imgsize("$basename-sm.jpg"); # Spit out the html for the image and link. $table_col_count++; if ($table_col_count == 2) { $table_col_count = 0; print "\n\n"; } print "\n\n"; $imagecount++; $ipagecount++; Log("Imagecount: $imagecount. Ipagecount: $ipagecount. Filecount: $filecount"); ############################ # # End of inner image loop. # ############################ } # end while print "\n
\n"; print< EOLINKS # Spit out the comments link if we need it. if ($comments) { print qq{\n
Comment} } # Spit out the catpion if there is one. if ($caption) { print "\n
$caption"; } # End the current image. #print "

\n"; print "\n

\n"; # Prepare the end the current page. Log("Resetting ipagecount."); $ipagecount = 0; # Do bottom navigation bar. print_navbar; # And the big footer. print_footer; select(STDOUT); close(HTML); $pagecounter++; Log("Pagecounter: $pagecounter."); if ($imagecount < $filecount) { goto FILELOOP; } } # end FILELOOP Log("Done."); close(LOG); exit; ### Subs sub Log($) { my $message = shift; print LOG "$message\n"; } sub gifn($) { my $num = shift @_; my $file; if ($num > 1) { $file = "index-$num.html"; } else { $file = "index.html"; } return $file; } sub print_navbar { if ($indexcount > 1) { # print the navigation bar in multi-file mode my $num; my $file; print "
"; print "
"; # Previous Link if ($pagecounter > 1) { $num = $pagecounter - 1; $file = gifn($num); print "<< Previous"; } print " [ "; for (1..$indexcount) { $file = gifn($_); if ($pagecounter != $_) { print "  $_  "; } else { print "   $_   "; } } print " ] "; # Next Link if ($pagecounter < $indexcount) { $num = $pagecounter + 1; $file = gifn($num); print "Next >>"; } print "
"; } } sub print_footer { print<
Updated on $timestamp
Copyright $year, Jeremy D. Zawodny <Jeremy\@Zawodny.com>
EOFOOTER } __END__