#!/usr/bin/perl # # This program will take a list of jpeg files and generate a # HTML document and imagemapped thumbnail of the files for preview. # # 6 Aug 1998 JV - Fixed the duplicate bug that broke some IE # 28 Jan 1998 mike- Feeped some Creatures # 6 Jan 1998 JV - hangnail with getopt! # 23 Mar 1996 JV - For jpeg files # 10 Jan 1996 JV - Created # use Getopt::Std; # # Set up the defaults. # $opt_f = "index.html"; $opt_w = 5; $opt_h = 2; $opt_x = 120; $opt_y = 120; $opt_b = 10; $opt_p = "HangNail_"; $opt_n = 1; $opt_c = "ffffff"; $opt_C = "000000"; $opt_o = "order.txt"; $opt_J = "-quality 25"; # Get the options (if any) $options = 'w:h:x:y:f:t:J:p:n:c:C:Sb:o:'; getopts($options); $htmlfile = $opt_f; $title = $opt_t; $num_wide = $opt_w; $num_high = $opt_h; $width = $opt_x; $height = $opt_y; $thumbname = $opt_p; $thumb_num = $opt_n; $color = $opt_c; $textcolor = $opt_C; $jpegoptions = $opt_J; $spam = $opt_S; $border = $opt_b; $order_file = $opt_o; $date = `date`; $username = `whoami`; $images = $#ARGV+1; if ($images < 1 && ! -f $order_file ) { print(STDERR "\n"); print(STDERR "HangNail $version by Johnathan Vail (vail\@newts.org)\n\tWith Creatures Feeped by Mike Sullivan (mike\@newts.org)\n"); print(STDERR "Usage:\n\n"); print(STDERR "hangnail [-OPTIONS] [JPEG FILES]\n"); print(STDERR " where OPTIONS are any of -$options\n"); print(STDERR " -f FILE\t\tSpecify the html file to create (\"$opt_f\")\n"); print(STDERR " -t \"title text\"\tDescription for web page title (\"$opt_t\")\n"); print(STDERR " -o FILE\t\tFile containing FILENAME:CAPTION lines for each image (\"$opt_o\")\n"); print(STDERR " -w N\t\t\tNumber of thumbnails wide per image ($opt_w)\n"); print(STDERR " -h N\t\t\tNumber of thumbnails high per image ($opt_h)\n"); print(STDERR " -x N\t\t\tWidth of each thumbnail in pixels ($opt_x)\n"); print(STDERR " -y N\t\t\tHeight of each thumbnail in pixels ($opt_y)\n"); print(STDERR " -b N\t\t\tBorder around each thumbnail in pixels ($opt_b)\n"); print(STDERR " -p NAME\t\tFilename prefix to use for thumbnail images ($opt_p)\n"); print(STDERR " -n N\t\t\tNumber to start the thumbnail images ($opt_n)\n"); print(STDERR " -c RRGGBB\t\tHex color specifying background color ($opt_c)\n"); print(STDERR " -C RRGGBB\t\tHex color specifying text color ($opt_C)\n"); print(STDERR " -J \"[options]\"\t\tOptions to pass to the \`cjpeg\` program (\"$opt_J\")\n"); print(STDERR " -S\t\t\tSuppress HangNail advertising\n"); print(STDERR "\n"); exit 1; } if ( -f $order_file ) { # If there is a file matching the $order_file filename open it # and extract all the NAME:CAPTION pairs. Stuff the names onto # the ARGV list and hash the CAPTIONs by NAME. It might be nice # to make sure the file is not already on the ARGV list, but as # long as the user uses one method or the other of specifying files # everything should be hunky-dorey. open ORDERINFO, "<$order_file"; while () { ($filename,$text) = /([^:]*):(.*)/; if ( $filename ) { $caption{ $filename } = $text; @ARGV = ( @ARGV, $filename ); } #print STDERR "$filename $caption{$filename}\n"; } close ORDERINFO; } open(STDOUT, ">$htmlfile"); print "\n"; print "\n"; print "\n"; print " $title \n"; print "\n\n"; print "\n\n"; print "


$title

"; print " $date by $username


\n\n"; print "
\n"; print "
\n"; print "\n
"; $row_height = 2 * $border + $height; $map_height = $row_height * $num_high; $map_width = (2 * $border + $width) * $num_wide; $row = 0; $col = 0; foreach $file ( @ARGV ) { next unless -f $file; if ( $col == 0 ) { if ($row == 0) { print "\n"; } system("ppmmake \"#$color\" $map_width $row_height > row_$row.ppm"); } $ipath = substr( $file, 0, $start = 1 + rindex($file,"/") ); $jname = substr( $file, $start ); system("djpeg -pnm < $file | /usr/bin/pnmscale -xysize $width $height > thumbi.pnm"); # Let's find out how big this file is open SIZEINFO, "; #Get rid of filetype ( we don't care ) $foo = ; ($icn_width, $icn_height) = $foo =~ /(\d*) (\d*)/; close SIZEINFO; $slop_width = $width - $icn_width; $slop_height = $height - $icn_height; $x = ($slop_width / 2) + $col * ( 2 * $border + $width ) + $border; $sx = ($x + $icn_width) -1; $y = ($slop_height / 2) + $row * $row_height + $border; $sy = ($y + $icn_height) -1; $cap = $jname unless ( $cap = $caption{ $file } ); print "\n"; $v_offset = $slop_height /2 + $border; system("pnmpaste thumbi.pnm $x $v_offset row_$row.ppm > row_$row.pnm"); system("mv row_$row.pnm row_$row.ppm"); $col++; if ( $col == $num_wide ) { $row++; $col = 0; } if ( $row == $num_high ) { print("\n"); system("pnmcat -white -top row_*.ppm | tee thumbtmp.pnm | cjpeg $jpegoptions > $thumbname$thumb_num.jpg"); open SIZEINFO, "; #Get rid of filetype ( we don't care ) $foo = ; ($icn_width, $icn_height) = $foo =~ /(\d*) (\d*)/; close SIZEINFO; print "\n"; print "


\n"; system("rm row_*.ppm thumbtmp.pnm thumbi.pnm"); $thumb_num++; $row = 0; } } if ( $row || $col ) { # Take care of any unfinished business print("\n"); system("pnmcat -white -top row_*.ppm | tee thumbtmp.pnm | cjpeg $jpegoptions > $thumbname$thumb_num.jpg"); open SIZEINFO, "; #Get rid of filetype ( we don't care ) $foo = ; ($icn_width, $icn_height) = $foo =~ /(\d*) (\d*)/; close SIZEINFO; print "\n"; print "


\n"; system("rm row_*.ppm thumbtmp.pnm thumbi.pnm"); } print "
\n"; if (!$spam) {print "


Made by HangNail\n";} print "\n"; print "\n";