#!/usr/bin/perl -w # # David Wakeman, 2001 # http://www.gibfest.org/ # djw@gibfest.org # # Utility to sort a bunch of image's into formatted html pages # so they can be viewed through a web browser. Also includes # the ability to write comments for each picture - requires # user input. # # shtml assumes apache with Inlcudes module loaded. I have no # clue how other web servers deal with this type of thing. use strict; my( $web_file, $webpage_dir, $comment, $comments, $file, $logo ); my( @pictures, $num_pics, $pic, $pics_page, $image_type, $image_dir); my( $file_copy, $creation_answer, $page_num, $menu, $footer); my( $pic_dir, $creation_answer2, @new_pictures, $header, $logo_question ); # # Configuration area. Please enter everything you need or require # here. You shouldn't need to edit past this point. Please keep # all answers lowercase. I'm too lazy to check for that right now # # These are all the directories we need to define. $image_dir # is where you want to grab the images from. $webpage_dir is # where you will put your shtml files. And $pics_dir is where # the images will be copied to. $image_dir = "/home/djw/Perl/work/images"; $webpage_dir = "/var/www/pictures"; $pics_dir = "images"; # # File name to use for each page. This will be incremented for each page you # have depending on how many pics you have, and how many pics you want displayed # per page. Also, define the image type you want to use (case sensitive for now) $web_file = "pictures"; $image_type = "jpg"; # # How many pics do you want displayed per page. $pics_page = 10; # # Do you want this program to copy your images over to the webidr? yes or no only. $file_copy = "yes"; # # Answer here if you would like to include comments under each pic. yes or no only. $comments = "no"; # # Name of your server-side includes files $header = "header.shtml"; $menu = "menu.shtml"; $footer = "footer.shtml"; # # Answer here if you would like a logo, if yes, then enter the logo name $logo_question = "yes"; $logo = "pictures.jpg"; # # No touchy after this point unless you know what you are # doing. If you do know, then please let ME know what cool # things you have done. $pic = ""; $creation_answer = ""; $creation_answer2 = ""; $comment = ""; $page_num = 1; dir_glob(); create_dirs(); write_web(); sub dir_glob { opendir( IDIR, "$image_dir" ) || die "Can't open $image_dir for reading: ($!)\n"; foreach $file ( readdir( IDIR ) ) { if ($file =~ /(.*?)\.$image_type/ ) { push(@pictures, $file); } } closedir( IDIR ); $num_pics = @pictures; } sub create_dirs { if ( -d "$webpage_dir/$pic_dir" ) { if ( $file_copy eq "yes" ) { print "Copying files....\n"; copy_files(); } } else { print "Directory $webpage_dir doesn't exist.\n"; print "Want to create the \$web_dir: $webpage_dir (yes or no)? "; chomp ( $creation_answer = ); if ( $creation_answer eq "yes" ) { mkdir( "$webpage_dir", 0775 ) || die "Can't create $webpage_dir: ($!)\n"; } else { print "Skipping $webpage_dir creation.\n"; } print "Directory $webpage_dir/$pic_dir doesn't exist.\n"; print "Want to create it (yes or no)? "; chomp( $creation_answer2 = ); if ( $creation_answer2 eq "yes" ) { mkdir( "$webpage_dir/$pic_dir", 0775 ) || die "Can't create $webpage_dir/$pic_dir: ($!)\n"; if ( $file_copy eq "yes" ) { print "$webpage_dir/$pic_dir is there, now to copy files.\n"; print "Copying files.....\n"; copy_files(); } } else { print "Doesn't look like you have $webpage_dir/$pic_dir and I won't create it, exiting\n"; exit; } } } sub copy_files { system( "cp $image_dir/*.$image_type $webpage_dir/$pic_dir" ); print "Done.\n"; } sub write_web { if ( $num_pics <= $pics_page ) { write_single_shtml(); } elsif ( $num_pics > $pics_page ) { write_multi_shtml(); } } sub write_single_shtml { open( SHTML, "+>$webpage_dir/$web_file$page_num.shtml" ) || die "Can't open file for writing: ($!)\n"; print SHTML "\n"; print SHTML "\n"; if ($logo_question eq "yes") { print SHTML "\n"; } print SHTML "
"; print SHTML "Automatic Pic Viewer by: David Wakeman, 2001
\n"; print SHTML "
\n"; foreach $pic ( @pictures ) { print SHTML "
\n"; if ( $comments eq "yes" ) { print "What is the comment for $pic? "; chomp( $comment = ); print SHTML "[ $comment ]\n"; print SHTML "

\n"; } else { print SHTML "[ $pic ]\n"; print SHTML "

\n"; } } print SHTML "
\n"; print SHTML "\n"; close( SHTML ); print "Done.\n"; } sub write_multi_shtml { open( MENU, "+>$webpage_dir/$menu" ) || die "Can't open menu for writing: ($!)\n"; print MENU "
\n"; print MENU "
\n"; while (@pictures) { @new_pictures = splice(@pictures, 0, $pics_page); open( SHTML, "+>$webpage_dir/$web_file$page_num.shtml" ) || die "Can't open file for writing: ($!)\n"; print SHTML "\n"; print SHTML "\n"; if ($logo_question eq "yes") { print SHTML "\n"; } print SHTML "
"; print SHTML "Automatic Pic Viewer by: David Wakeman, 2001
\n"; print SHTML "\n"; print SHTML "
\n"; foreach $pic ( @new_pictures ) { print SHTML "
\n"; if ( $comments eq "yes" ) { print "What is the comment for $pic? "; chomp( $comment = ); print SHTML "[ $comment ]\n"; print SHTML "

\n"; } else { print SHTML "[ $pic ]\n"; print SHTML "

\n"; } } print SHTML "
\n"; print MENU " -[ Page $page_num ]-"; print SHTML "\n"; print SHTML "\n"; $page_num++; } print MENU "
\n"; print MENU "

\n"; close( SHTML ); close( MENU ); print "Copied $num_pics images to $webpage_dir/$pic_dir/\n"; print "Done writing $page_num shtml to $webpage_dir.\n"; }