#!/usr/local/bin/perl ############################################################################## $VERSION='gif2html.pl v1.1'; # 24 Oct. 1996 Dale Bewley # v1.0 Oct. 96, v1.0b4 25 July 96, v.99 12 June 96, v.09 26 Sept. 95 #----------------------------------------------------------------------------- # # This script and others found at http://www.bewley.net/perl/ # # Creates an html file for each graphic in a directory. Usefull for creating # a slide show. See slideshow.pl on my perl page above. # # Fairly New stuff: # o I just added some POD to the bottom. # o Adds width and height tags to gifs and jpegs. # o Template support! Now the html is not hardcoded in the program. You # create a template file with an empty img tag like and that # will be replaced with an . Simple as that! # Also in your template you can have an tag to be # replaced with a caption for that image. See the default template in # sub readTemplate for an example. # # To sum up there are 3 ways gif2html will insert data in a template. # These will probably change too... # 1. # 2. # 3. # # o Caption support! Create a caption file like so: # # filename.gif|Text of caption. # # ONE line of info per image. Each line will be "chopped". # This will be read into a hash. In your template will # be replaced by the caption for that image. # # Todo: # o Replace the tag with a dbewley html extension of # some sort or just a gif2html tag... # o Clean up. # o Perhaps change caption mechanism. # o Make callable from slideshow.pl and other programs and CGI. # # Notes: # o Tested with UNIX of course and also Win95 Perl5.001m b107 # # o Give your graphics descriptive names. Use full words seperated by # a '-'. Dashes will be converted to spaces and possibly placed in the # title depending on your template. Better yet, use the captions. # # # Copyright (C) 1995, 1996 Dale Bewley # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ############################################################################## #- User Configurable Variables ----------------------------------------------# #$BACKGROUND = "http://www.iupui.edu/home/Graphics/emboss.gif"; $CAPTION_FILE = ".gif2html.cap"; # default file of captions $TEMPLATE_FILE = ".gif2html.tmp"; # default HTML template in current dir $BASEREF = "./"; # to prefix IMG SRC's #----------------------------------------------------------------------------# #- Help! --------------------------------------------------------------------# sub help { # help a lost soul print < http://www.bewley.net/perl/gif2html.html Description: This script will create an HTML file for each of a batch of graphics. Usage: $0 [] Options: -b Baseref for all URLs in output. -g Background for output files (unused) -c .gif2html.cap Use this file for caption mappings. -h This message. -t .gif2html.tmp Use this template file. -v Verbose. Filespec: Any pattern that names your graphics, i.e. luther.gif *.gif *.jpg * *.* Example: $0 -c captions.txt -v *.gif *.jpg E_O_HELP 1; } #----------------------------------------------------------------------------# #- Main Program -------------------------------------------------------------# require('getopt.pl') || print STDERR "Waring! get getopt.pl\n"; &getOpts; # get commandline options if ((!$ARGV[0]) || ($opt_h)) { &help && exit; } # give help and exit? @gfxFiles = @ARGV; # queue up the gfx print STDERR scalar(@gfxFiles), " gfx to process\n" if ($opt_v); @TEMPLATE = &readTemplate($TEMPLATE_FILE); # read html template %CAPTIONS = &readCaptions($CAPTION_FILE); # read gfx captions foreach (@gfxFiles) { &writeFile($_,@TEMPLATE); } # write the html files #----------------------------------------------------------------------------# #- Get Command Line Opts ----------------------------------------------------# sub getOpts { &Getopt('cbgt'); # these options accept commandline values $BASEREF = $opt_b if ($opt_b); $CAPTION_FILE = $opt_c if ($opt_c); $BACKGROUND = $opt_g if ($opt_g); # unused! $TEMPLATE_FILE = $opt_t if ($opt_t); } #----------------------------------------------------------------------------# #- Read HTML Template -------------------------------------------------------# sub readTemplate { # get html template to put graphics into. local($template) = shift @_; local(@template); if (open(TEMPLATE, "$template")) { print STDERR "reading template file: $template\n" if ($opt_v); @template =