#! /usr/bin/perl -w #----------------------------------------------------------- # creates a web photo album # must have file structure: # dir/ # thumbs/ # fullsize/ # where "dir" is the current directory containing subdirectories (call it anything) # directory thumbs contains thumbnail images # directory fullsize contains full size images # creates a directory called pages containing the pages for each individual image # creates a file called index.html (the navigation page) #----------------------------------------------------------- # to make getting the basename of the dir easy use File::Basename; # write the index.html page if (-e "index.html") { print "\nindex.html already exists. I refuse to overwrite and make an error you will regret later.\n"; print "You will need to delete this file manually and run me again.\n\n"; exit; } # list of jpeg and gif files in current dir @files = `ls thumbs/*.jpg thumbs/*.gif`; $numfiles = @files; # mangle the list of files to delete the "thumbs/" @filez = (); foreach $file (@files) { $filename = basename($file); chomp $filename; push @filez, $filename; } # get directory name $dirname = basename(`pwd`); chomp $dirname; # make a "pages" dir for individual pages if (! -e "pages") { system("mkdir pages"); } open(MASTERPAGE, '>index.html'); print MASTERPAGE "\n"; print MASTERPAGE "\n"; print MASTERPAGE "\n"; print MASTERPAGE "Web Photo Album: $dirname\n"; print MASTERPAGE "\n"; print MASTERPAGE "\n"; print MASTERPAGE "\n"; print MASTERPAGE "
\n"; print MASTERPAGE "

\n"; print MASTERPAGE "Web Photo Album: $dirname\n"; print MASTERPAGE "

\n"; print MASTERPAGE "\n"; # use a count for determining the number of columns of thumbnails $count = 0; # use a count of images $next = 0; # create a page for each image foreach $file (@filez) { # get the previous and next files $next = $next + 1; $prev = $next - 2; $prevfile = "$filez[$prev].html"; if ($next < $numfiles) { $nextfile = "$filez[$next].html"; } # write the individual image page open(IMAGEPAGE, ">pages/$file.html"); print IMAGEPAGE "\n"; print IMAGEPAGE "\n"; print IMAGEPAGE "\n"; print IMAGEPAGE "$file\n"; print IMAGEPAGE "\n"; print IMAGEPAGE "\n"; print IMAGEPAGE "\n"; print IMAGEPAGE "
\n"; print IMAGEPAGE "

\n"; print IMAGEPAGE "$file\n"; print IMAGEPAGE "

\n"; # navigation print IMAGEPAGE "Index\n"; if ($next != 1) { print IMAGEPAGE "Previous\n"; } if ($next < $numfiles) { print IMAGEPAGE "Next\n"; } print IMAGEPAGE "
\n"; print IMAGEPAGE "
\n"; # the image print IMAGEPAGE "
\n"; print IMAGEPAGE "
"; print IMAGEPAGE "
\n"; print IMAGEPAGE "
\n"; print IMAGEPAGE "Generated by \n"; print IMAGEPAGE "webphoto.pl\n"; print IMAGEPAGE "
\n"; print IMAGEPAGE "\n"; print IMAGEPAGE "\n"; # the URL of the individual page $url = " \n"; # start creating the table structure if ($count eq 0) { print MASTERPAGE "\n"; print MASTERPAGE "$url"; $count = $count + 1; } elsif (($count < 3) ) { print MASTERPAGE "$url"; $count = $count + 1; } else { print MASTERPAGE "$url"; print MASTERPAGE "\n"; $count = 0; } #$count = $count + 1; close IMAGEPAGE; } # end the HTML print MASTERPAGE "\n\n
\n"; print MASTERPAGE "


\n"; print MASTERPAGE "
\n"; print MASTERPAGE "Generated by \n"; print MASTERPAGE "webphoto.pl\n"; print MASTERPAGE "
\n"; print MASTERPAGE ""; print MASTERPAGE ""; close MASTERPAGE;