Old changes (forgot to commit):

Read names and positions of gif images from stdin.
Doesn't create HTML file any more.

New change:
Send stderr to /tmp/fotoindex.$$.debug
This commit is contained in:
hjp 1998-08-26 10:35:16 +00:00
parent 945181f016
commit 64c1b0e561
2 changed files with 51 additions and 121 deletions

13
fotoindex/GNUmakefile Normal file
View File

@ -0,0 +1,13 @@
include GNUmakevars
include GNUmakerules
fotoindex:
install: /usr/local/bin/fotoindex
/usr/local/man/man8/%.8: %.man
$(INSTALL) $< $@
clean:
rm -f *.gif *.jpg core foo bar baz

View File

@ -1,140 +1,57 @@
#!/usr/local/bin/perl #!/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.
sub splitfields { open(STDERR, ">/tmp/fotoindex.$$.debug");
my ($line) = @_;
my @result = ();
my $field;
$off = 0;
$field =~ s/\r?\n//;
for (;;) {
if (substr($line, $off, 1) eq '"') {
$noff = index($line, '"', $off+1);
if (!$noff) {
print STDERR "$0: splitfields: unterminated field at line $.\n";
exit(1);
}
$field = substr($line, $off+1, $noff - $off - 1);
push (@result, $field);
#print "splitfields: found field = $field\n";
$off = $noff + 1;
} else {
if ($noff = index($line, ';', $off)) {
$field = substr($line, $off, $noff - $off);
$off = $noff;
} else {
$field = substr($line, $off);
$off = length($line);
}
push (@result, $field);
#print "splitfields: found field = $field\n";
}
if (substr($line, $off, 1) ne ';') { return @result }
$off++;
}
return @result;
}
$telreg = "/usr/local/www/offline/wifo/skel/telreg.txt";
$fotodir = "/usr/local/www/wifo/fotos";
$giftopnm = "/usr/local/bin/giftopnm"; $giftopnm = "/usr/local/bin/giftopnm";
$pnmcat = "/usr/local/bin/pnmcat";
$pnmfile = "/usr/local/bin/pnmfile";
$pnmscale = "/usr/local/bin/pnmscale"; $pnmscale = "/usr/local/bin/pnmscale";
$ppmquant = "/usr/local/bin/ppmquant"; $pbmmake = "/usr/local/bin/pbmmake";
$ppmtogif = "/usr/local/bin/ppmtogif"; $pnmpaste = "/usr/local/bin/pnmpaste";
$cjpeg = "/usr/local/bin/cjpeg"; $cjpeg = "/usr/local/bin/cjpeg";
chdir($fotodir) or die "cannot cd to $fotodir: $!"; if ($ARGV[0] eq "-o") {
shift;
open (TELREG, $telreg) or die "cannot open $telreg: $!"; $outputredirect = ">" . shift;
$fields = <TELREG>;
@fields = splitfields($fields);
for ($i = 0; $i <= $#fields; $i++) {
if ($fields[$i] eq "Familienname") {
$sni = $i;
} elsif ($fields[$i] eq "Vorname") {
$fni = $i;
} elsif ($fields[$i] eq "login") {
$lni = $i;
}
} }
while (<TELREG>) { @file = (<>);
@fields = splitfields($_); chomp(@file);
$login = $fields[$lni]; # Remove empty and comment lines
#print "$login"; for ($i = 0; $i <= $#file;) {
if (-f "$login.gif") { if ($file[$i] =~ m/^(\#|\s*$)/ ) {
#print " exists"; splice(@file, $i, 1);
$surname{$login} = $fields[$sni];
$firstname{$login} = $fields[$fni];
}
#print "\n";
}
@sortedlogins = sort { "${surname{$a}} ${firstname{$a}}" cmp "${surname{$b}} ${firstname{$b}}" } keys(%surname);
$fw = 9;
$fh = int(($#sortedlogins + 1 + ($fw - 1)) / $fw);
$protogif = $sortedlogins[0] . ".gif";
open (PNMFILE, "$giftopnm $protogif | $pnmfile |")
or die "cannot get size of $protogif: $!";
$pnmfileout = <PNMFILE>;
close($pnmfile);
if ($pnmfileout =~ m/P[PGB]M raw, (\d+) by (\d+) maxval/) {
$gifw = int ($1 / 2);
$gifh = int ($2 / 2);
} else { } else {
printf STDERR "$0: cannot size from pnmfile output $pnmfileout\n"; $i++;
exit(1); }
} }
open(HTML, ">map.html") or die "cannot open map.html for writing: $!"; $tnw = shift(@file);
$tnh = shift(@file);
$fw = shift(@file);
$fh = int(($#file + 1 + ($fw - 1)) / $fw);
print HTML "<html><head><title>Wifo: Photo Gallery</title></head>\n"; system ("$pbmmake " . $fw * $tnw . " " . $fh * $tnh . "> /tmp/fotoindex.$$.1.pnm");
print HTML "<body>\n";
print HTML qq| <img src="map.jpg" usemap="#map" width=|,
$fw * $gifw, qq| height=|, $fh * $gifh, qq| border=0>\n|;
print HTML qq|<map name="map">\n|;
@col = (); for ($i = 0; $i < $fh; $i ++) {
for ($i = 0; $i <= $#sortedlogins / $fw; $i ++) {
@row = ();
for ($j = 0; $j < $fw; $j++) { for ($j = 0; $j < $fw; $j++) {
$login = $sortedlogins[$i * $fw + $j]; $pic = $file[$i * $fw + $j];
if ($login ne "") { if (-f $pic) {
$sn = $surname{$login}; $cmnd = "$giftopnm $pic | $pnmscale -xysize $tnw $tnh > $pic.$$.pnm";
$fn = $firstname{$login}; system ($cmnd);
system ("$giftopnm $login.gif | $pnmscale 0.5 > $login.pnm"); system ("$pnmpaste $pic.$$.pnm " . $j * $tnw . " " . $i * $tnh . " /tmp/fotoindex.$$.1.pnm > /tmp/fotoindex.$$.2.pnm");
push (@row, "$login.pnm"); rename ("/tmp/fotoindex.$$.2.pnm", "/tmp/fotoindex.$$.1.pnm");
print HTML qq|<area shape=rect coords="|, unlink ("$pic.$$.pnm");
$j * $gifw, ",", $i * $gifh, " ",
($j+1) * $gifw - 1, ",", ($i + 1) * $gifh - 1,
qq{" href="$login.gif" alt="$fn $sn">\n};
} }
} }
system("$pnmcat -leftright " . join(" ", @row) . "> $i.pnm");
push (@col, "$i.pnm");
unlink (@row);
} }
print HTML "</map>\n"; system("$cjpeg -progressive /tmp/fotoindex.$$.1.pnm $outputredirect");
print HTML "</body>\n"; unlink ("/tmp/fotoindex.$$.1.pnm");
print HTML "</html>\n";
if (!close (HTML)) {
print "$0: error closing map.html: $!\n";
}
system("$pnmcat -topbottom -jleft -white " . join(" ", @col) . "| $cjpeg -progressive > map.jpg");