#!/usr/bin/perl -w ############################################################################## # set up thumbnail links # Author: Chris Rouch # Date: 2000-2003 # # Copyright (c) Chris Rouch 2000-2003 # # 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # or see http://www.gnu.org/licenses/gpl.txt ############################################################################## use strict; use Getopt::Long; use Image::Size; # constants use constant IMGDIR => "./images"; use constant IMGURL => "./images"; use constant BORDER => 2; use constant THUMBSIZE=>100; use constant DEFCOLS=>3; use constant PREFIX=>'s_'; # general global variables my ($PROG,$USAGE,$OPTIONS); # command line variables my $cols=DEFCOLS; my $verbose; # make some noise my $inline; # make an inline image my $imgdir=IMGDIR; # where to find the images my $imgurl=IMGURL; # (relative) url for the images my $prefix=PREFIX; # thumbnail prefix use vars qw ($thumb $img $str $linkstr $fthumb $fimg); use vars qw ($iwidth $iheight $twidth $theight $tabwidth @strs $count); # command line switch my %opts= ( "c|cols=i" => \$cols, "i|inline" => \$inline, "d|dir=s" => \$imgdir, "u|url=s" => \$imgurl, "p|prefix=s" => \$prefix, "v|verbose" => \$verbose, ); ($PROG=$0) =~ s#.*/##; SetUsage(\%opts,\$OPTIONS); $USAGE="Usage: $PROG $OPTIONS"; die "$USAGE\n" unless GetOptions(%opts); # program begins here $count=0; print "\n" unless ($inline); while (<>) { next if (/^#.*$/); # skip comments #format is 'image thumbnail text ...' if (/^\s*$/) { # blank line, output a space if ($inline) { # do nothing } else { print qq[   ]; $linkstr=''; push(@strs," "); } } else { chomp; ($img,$thumb,$str) = split(/\s+/,$_,3); print STDERR "Image: $img, Thumb: $thumb, Text: $str\n" if ($verbose); push(@strs,$str); $fthumb = "$imgdir/$thumb"; $fimg = "$imgdir/$img"; ($iwidth,$iheight)=imgsize($fimg); unless ($iheight) { warn "Can't get size for $fimg, skipping\n"; next; } ($twidth,$theight)=imgsize($fthumb); unless ($theight) { warn "Can't get size for $fthumb, skipping\n"; next; } $tabwidth= $twidth+BORDER; ($linkstr=$str) =~ s!\'!\\'!g; } if ($inline) { print qq[
$str

TEXT HOOK

]; } else { # not inline if ($linkstr) { print qq[ ]; } $count++; if (($cols) and ($count == $cols)) { # time for a new row print "\n\n\n"; foreach my $str (@strs) { # add captions print qq[$str\n]; } print "\n\n"; @strs=(); $count=0; } } } if ((!$inline) and ($cols) and ($#strs >= 0)) { # something left, so add a new line print "\n\n"; foreach my $str (@strs) { # add remaining captions print qq[$str\n]; } print "\n\n"; } ############### end of main ############# sub SetUsage { my ($ropts,$rstr) = @_; foreach my $key (keys %$ropts) { if ($key =~ /\|/) { $key=~ s!^.*\|!!; } if ($key =~ /=/) { $key =~ s!=.*$! value!; } $key = '-' . $key; $$rstr .= '[' . $key . '] '; } } ############### end of file #############