#!/usr/bin/perl
$base="http://math.univ-lyon1.fr/~logicum/photos/";

if ($#ARGV < 2) {
	print "usage: perl build.pl [directory] 300 3\n";
	exit;
}
$path=$ARGV[0];
$size=$ARGV[1];
$width=$ARGV[2];

while ($big = <$path/big/*>) { $sane = $big;
	$sane =~ s/\/big\//\/sane\//;
	system sprintf("convert -thumbnail $size $big $sane\n");
}

$i=0;
open(F,">$path/raw.html");
print F "<table align=center bgcolor=#edffaa border=0 cellspacing=0>\n";
while ($sane = <$path/sane/*>) { $big = $sane;
	$big =~ s/\/sane\//\/big\//;
	if ($i == 0) {  print F "<tr>\n";  }
	++$i;
	print F "<td>";
	$img = "<img src=$base$sane>";
	if (-e $big) {  print F "<a href=$base$big>$img</a>";  }
	else  {  print F $img;  }
	print F "</td>\n";
	if ($i >= $width) {  print F "</tr>\n";  $i=0;  }
}
print F "</table>\n";
close(F);

