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

if ($#ARGV < 3) {
	print "usage: perl build.pl [directory] 300 100 3\n";
	exit;
}
$path=shift;
$sizeBig=shift;
$sizeSmall=shift;
$width=shift;

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

$i=0;
open(F,">$path/raw.html");
print F "<table align=center bgcolor=#edffaa border=0 cellspacing=0>\n";
while ($small = <$path/small/*>) { $big = $small;
	$big =~ s/\/small\//\/big\//;
	if ($i == 0) {  print F "<tr>\n";  }
	++$i;
	print F "<td>";
	$img = "<img src=$base$small>";
	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);

