Initial release.

Still missing: Produce jpg instead of gif, produce links to real pages
instead of gifs.
This commit is contained in:
hjp 1998-05-12 08:12:38 +00:00
parent 8feacf8ee6
commit 08bde4065f
1 changed files with 139 additions and 0 deletions

139
fotoindex/fotoindex Executable file
View File

@ -0,0 +1,139 @@
#!/usr/local/bin/perl
sub splitfields {
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";
$pnmcat = "/usr/local/bin/pnmcat";
$pnmfile = "/usr/local/bin/pnmfile";
$pnmscale = "/usr/local/bin/pnmscale";
$ppmquant = "/usr/local/bin/ppmquant";
$ppmtogif = "/usr/local/bin/ppmtogif";
chdir($fotodir) or die "cannot cd to $fotodir: $!";
open (TELREG, $telreg) or die "cannot open $telreg: $!";
$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>) {
@fields = splitfields($_);
$login = $fields[$lni];
#print "$login";
if (-f "$login.gif") {
#print " exists";
$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 {
printf STDERR "$0: cannot size from pnmfile output $pnmfileout\n";
exit(1);
}
open(HTML, ">map.html") or die "cannot open map.html for writing: $!";
print HTML "<html><head><title>Wifo: Photo Gallery</title></head>\n";
print HTML "<body>\n";
print HTML qq| <img src="map.gif" 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 <= $#sortedlogins / $fw; $i ++) {
@row = ();
for ($j = 0; $j < $fw; $j++) {
$login = $sortedlogins[$i * $fw + $j];
if ($login ne "") {
$sn = $surname{$login};
$fn = $firstname{$login};
system ("$giftopnm $login.gif | $pnmscale 0.5 > $login.pnm");
push (@row, "$login.pnm");
print HTML qq|<area shape=rect coords="|,
$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";
print HTML "</body>\n";
print HTML "</html>\n";
if (!close (HTML)) {
print "$0: error closing map.html: $!\n";
}
system("$pnmcat -topbottom -jleft -white " . join(" ", @col) . "| $ppmquant 256 | $ppmtogif > map.gif");