Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/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_questio +n ); # # 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 p +age 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 sensitiv +e 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. y +es 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 na +me $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 re +ading: ($!)\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 = <STDIN> ); if ( $creation_answer eq "yes" ) { mkdir( "$webpage_dir", 0775 ) || die "Can't create $webpag +e_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 = <STDIN> ); if ( $creation_answer2 eq "yes" ) { mkdir( "$webpage_dir/$pic_dir", 0775 ) || die "Can't creat +e $webpage_dir/$pic_dir: ($!)\n"; if ( $file_copy eq "yes" ) { print "$webpage_dir/$pic_dir is there, now to copy fil +es.\n"; print "Copying files.....\n"; copy_files(); } } else { print "Doesn't look like you have $webpage_dir/$pic_dir an +d 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 "C +an't open file for writing: ($!)\n"; print SHTML "<!--#include virtual=\"$header\"-->\n"; print SHTML "<table border=\"0\" width=\"100%\"><tr><td align=\"le +ft\" width=\"50%\" valign=\"top\">"; print SHTML "Automatic Pic Viewer by:<b> David Wakeman, 2001</b></ +td>\n"; if ($logo_question eq "yes") { print SHTML "<td align=\"right\" width=\"%50\"><img src=\"$log +o\" border=\"0\" align=\"right\"></td>\n"; } print SHTML "</tr></table>\n"; print SHTML "<center>\n"; foreach $pic ( @pictures ) { print SHTML "<img src=\"$pic_dir/$pic\" border=\"0\"><br>\n"; if ( $comments eq "yes" ) { print "What is the comment for $pic? "; chomp( $comment = <STDIN> ); print SHTML "[ $comment ]\n"; print SHTML "<br><br>\n"; } else { print SHTML "[ <font size=\"1\" face=\"arial\">$pic</font> + ]\n"; print SHTML "<br><br>\n"; } } print SHTML "</center>\n"; print SHTML "<!--#include virtual=\"$footer\"-->\n"; close( SHTML ); print "Done.\n"; } sub write_multi_shtml { open( MENU, "+>$webpage_dir/$menu" ) || die "Can't open menu for w +riting: ($!)\n"; print MENU "<center>\n"; print MENU "<hr width=\"400\">\n"; while (@pictures) { @new_pictures = splice(@pictures, 0, $pics_page); open( SHTML, "+>$webpage_dir/$web_file$page_num.shtml" ) || di +e "Can't open file for writing: ($!)\n"; print SHTML "<!--#include virtual=\"$header\"-->\n"; print SHTML "<table border=\"0\" width=\"100%\"><tr><td align= +\"left\" width=\"50%\" valign=\"top\">"; print SHTML "Automatic Pic Viewer by:<b> David Wakeman, 2001</ +b></td>\n"; if ($logo_question eq "yes") { print SHTML "<td align=\"right\" width=\"%50\"><img src=\" +$logo\" border=\"0\" align=\"right\"></td>\n"; } print SHTML "</tr></table>\n"; print SHTML "<!--#include virtual=\"$menu\"-->\n"; print SHTML "<center>\n"; foreach $pic ( @new_pictures ) { print SHTML "<img src=\"$pic_dir/$pic\" border=\"0\" width +=\"400\" height=\"268\"></a><br>\n"; if ( $comments eq "yes" ) { print "What is the comment for $pic? "; chomp( $comment = <STDIN> ); print SHTML "[ $comment ]\n"; print SHTML "<br><br>\n"; } else { print SHTML "[ <font size=\"1\" face=\"arial\">$pic</f +ont> ]\n"; print SHTML "<br><br>\n"; } } print SHTML "</center>\n"; print MENU " -[ <a href=\"$web_file$page_num.shtml\">Page $ +page_num</a> ]-"; print SHTML "<!--#include virtual=\"$menu\"-->\n"; print SHTML "<!--#include virtual=\"$footer\"-->\n"; $page_num++; } print MENU "</center>\n"; print MENU "<br><hr width=\"400\">\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"; }

In reply to SHTML generator for image viewing by djw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (3)
    As of 2015-07-06 00:14 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (68 votes), past polls