#!/usr/bin/perl -w use strict; use Getopt::Std; use POSIX qw(ceil); my %opt = ( w => 120, h => 90, b => 1, n => 6, B => "white", m => 0, f => ".index", H => "", q => 0, s => 0, t => "", T => "", v => 0, ); getopts('w:h:H:b:n:B:mf:qst:T:v', \%opt); exit 0 unless @ARGV; @ARGV = sort @ARGV if $opt{s}; my @files = @ARGV; @files = map { if($opt{t}) { if(-f "$opt{t}/$_") { # look for thumbs $_ = "$opt{t}/$_"; } elsif (/(.*)\.(gif|bmp)$/) { $_ = "$opt{t}/$1.jpg" if -f "$opt{t}/$1.jpg"; } } s/\.gif$/.gif[0]/; # extract first frame from from animated gifs s/'/'\\''/g; # quote ' $_ = "'$_'"; # quote filenames } @files; my $files = join " ", @files; print "Schreibe" unless $opt{q}; unless($opt{m}) { my $rows = ceil (scalar (@files) / $opt{n}); my $command = "montage -geometry $opt{w}x$opt{h}+$opt{b}+$opt{b} -background '$opt{B}' -tile $opt{n}x$rows -adjoin $files $opt{f}.jpg"; print "$command\n" if $opt{v}; print " $opt{f}.jpg..." unless $opt{q}; system $command; } my $map = "$opt{f}-map.html"; print " $map...\n" unless $opt{q}; open MAP, ">$map" or die "$map: $!"; my $name = $opt{f}; $name =~ s!.*/!!; print MAP "\n"; my $n = 0; foreach (@ARGV) { my $left = ($n % $opt{n}) * ($opt{w}+2*$opt{b}); my $right = $left + ($opt{w}+$opt{b}); my $top = int($n / $opt{n}) * ($opt{h}+2*$opt{b}); my $bottom = $top + ($opt{h}+$opt{b}); my $href = $_; my $title = $_; if($opt{H}) { eval "\$href =~ $opt{H}"; } if($opt{T}) { eval "\$title =~ $opt{T}"; } print MAP " \"$title\"\n"; $n++; } print MAP "\n"; print MAP "\n"; close MAP; =head1 NAME make-indexjpg - creates thumbnail image and corresponding HTML map file =head1 SYNOPSIS B [I<-w> B] [I<-h> B] [I<-b> B] [I<-n> B] [I<-B> B] [I<-m>] [I<-f> B] [I<-H> B] [I<-T> B] [I<-q>] [I<-s>] [I<-t> B] [I<-v>] B ... =head1 DESCRIPTION B takes a list of image file names and uses B to create an image with thumbnails. A correspoding HTML map file can be used to make the index image clickable. =head1 OPTIONS =head2 I<-w> B I<-h> B The thumbnails inside the index image will have size B * B pixels. [120 * 90] =head2 I<-b> B Put a border of B pixels around each image. [1] =head2 I<-n> B Arrange the thumbnails in a grid with B columns. [6] =head2 I<-B> B Background color to use. [white] =head2 I<-m> Only generate the B-map.html file, omit B.jpg. [generate both] =head2 I<-f> B Name the index image B.jpg and the HTML map file B-map.html. [.index.jpg, .index-map.html] =head2 I<-H> B Apply perl regexp to filenames before writing href attributes. Example: -H 's/(.*)/images\/$1/'. [do not] =head2 I<-T> B Apply perl regexp to filenames before writing alt and title attributes. Example: -T 's/(.*)\.jpg/Picture of $1/'. [do not] =head2 I<-q> Be quiet. [print names of files written] =head2 I<-s> Sort the list of images given. [do not] =head2 I<-t> B Look for precomputed thumbnails in B. Use this to speed up the B call. [no thumbnails] =head2 I<-v> Be verbose, print commands as they are executed. [do not] =head1 AUTHOR Christoph Berg