#!/bin/perl -w

$MAX_COL = 5 ;

$email = "zoonek\@math.jussieu.fr" ;

$TRUE = (0==0) ;
$FALSE = (0==1) ;

############################################################################

opendir(DIR, "./") || die "cannot open current directory: $!";
@fichiers=();
while($_=readdir(DIR)) {
  next unless m/\.(gif|jpg)$/ ;
  next if m/thumb/ ;
  push @fichiers, $_;
}
closedir(DIR);

# Création des petites images
foreach $fichier (@fichiers) {
  system "convert", "-geometry", "160x100", $fichier, "thumb_$fichier";
}

# Création du fichier html
open(HTML,">index.html");
## En -tete du fichier
print HTML "<HTML><HEAD><TITLE>Images</TITLE>\n";
print HTML '<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">'
 . "\n" ;
print HTML "</HEAD><BODY><H1> Images </H1><HR>\n"; 
print HTML "<TABLE>\n";

$entre_deux_lignes = $TRUE ;
$col = 0;
foreach (@fichiers) {
  if($entre_deux_lignes){
    $entre_deux_lignes = $FALSE ;
    print HTML "<TR>\n";
    $col = 0;
  }
  print HTML "<TD>";
  print HTML "<A HREF=\"$_\">" ;
  print HTML "<IMG HEIGHT=100 WIDTH=160 SRC=\"thumb_$_\">" ;
  print HTML "</TD>\n" ;
  $col++ ;
  if($col>=$MAX_COL) { 
    print HTML "</TR>\n" ;
    $entre_deux_lignes = $TRUE ;
  }
}
if(! $entre_deux_lignes) {
  print HTML "</TR>\n";
}

## Fin du fichier
print HTML "</TABLE>\n\n";
print HTML "<HR><PRE>\n" ;
print HTML "<A HREF=\"doit.pl\">automatically generated</A>\n";
print HTML "on <TT>" . `date` ."</TT>\n" ;
print HTML "</PRE>";
print HTML "<ADDRESS><A HREF=\"mailto:$email\">$email</A>";
print HTML "</BODY></HTML>\n" ;

close(HTML);
