diff --git a/fotoindex/fotoindex b/fotoindex/fotoindex new file mode 100755 index 0000000..52d5e93 --- /dev/null +++ b/fotoindex/fotoindex @@ -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 = ; +@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 () { + @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 = ; +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 "Wifo: Photo Gallery\n"; +print HTML "\n"; +print HTML qq| \n|; +print HTML qq|\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|$fn $sn\n}; + } + } + system("$pnmcat -leftright " . join(" ", @row) . "> $i.pnm"); + push (@col, "$i.pnm"); + unlink (@row); + +} +print HTML "\n"; +print HTML "\n"; +print HTML "\n"; +if (!close (HTML)) { + print "$0: error closing map.html: $!\n"; +} +system("$pnmcat -topbottom -jleft -white " . join(" ", @col) . "| $ppmquant 256 | $ppmtogif > map.gif");