simple/fotoindex/fotoindex

58 lines
1.5 KiB
Perl
Executable File

#!/usr/local/bin/perl
#
# Combine several images into an index image (e.g., for use as an imagemap).
#
# Usage: fotoindex [-o outputfile] [templatefile]
#
# The first three lines give the width and height of the thumbnails and
# the number of thumbnails per row. The remaining lines are file names
# of the images to be combined.
open(STDERR, ">/tmp/fotoindex.$$.debug");
$giftopnm = "/usr/local/bin/giftopnm";
$pnmscale = "/usr/local/bin/pnmscale";
$pbmmake = "/usr/local/bin/pbmmake";
$pnmpaste = "/usr/local/bin/pnmpaste";
$cjpeg = "/usr/local/bin/cjpeg";
if ($ARGV[0] eq "-o") {
shift;
$outputredirect = ">" . shift;
}
@file = (<>);
chomp(@file);
# Remove empty and comment lines
for ($i = 0; $i <= $#file;) {
if ($file[$i] =~ m/^(\#|\s*$)/ ) {
splice(@file, $i, 1);
} else {
$i++;
}
}
$tnw = shift(@file);
$tnh = shift(@file);
$fw = shift(@file);
$fh = int(($#file + 1 + ($fw - 1)) / $fw);
system ("$pbmmake " . $fw * $tnw . " " . $fh * $tnh . "> /tmp/fotoindex.$$.1.pnm");
for ($i = 0; $i < $fh; $i ++) {
for ($j = 0; $j < $fw; $j++) {
$pic = $file[$i * $fw + $j];
if (-f $pic) {
$cmnd = "$giftopnm $pic | $pnmscale -xysize $tnw $tnh > $pic.$$.pnm";
system ($cmnd);
system ("$pnmpaste $pic.$$.pnm " . $j * $tnw . " " . $i * $tnh . " /tmp/fotoindex.$$.1.pnm > /tmp/fotoindex.$$.2.pnm");
rename ("/tmp/fotoindex.$$.2.pnm", "/tmp/fotoindex.$$.1.pnm");
unlink ("$pic.$$.pnm");
}
}
}
system("$cjpeg -progressive /tmp/fotoindex.$$.1.pnm $outputredirect");
unlink ("/tmp/fotoindex.$$.1.pnm");