#!/usr/athena/bin/perl

chdir "/var/http/Files/vermont";
$tocfile = ">index.html";
open (OUTPUT, $tocfile) || die "Can't open file $tocfile for writing\n";

print OUTPUT <<"END";

<HTML>
<BODY BACKGROUND="http://cascade.mit.edu/images/leatherfill.jpg">
<CENTER>
<FONT color="#EEBBAA" size="+3">
<IMG border="0" src="lefttwiddle.gif">
Vermont photo album
<IMG border="0" src="righttwiddle.gif">
<BR>
</FONT>
<FONT color="#EEBBAA" size="+1">
Click on a thumbnail for a closer look!
</FONT>
<P>
<TABLE border="2 cellspacing="5" cellpadding="5">
END

$currentcolumn = 0;
$maxcols = 3;

foreach $file (<*.jpg>) {
        &makeentry ($file, $currentcolumn);
        &makeicon ($file);
}

print OUTPUT <<"END";
</TABLE>
</CENTER>
<P>
<HR>
<FONT color="#EEBBAA">
Got a picture to add to this collection?  <A href="upload.html"> upload it! </A>
<BR>
Any questions? <A href="http://cascade.mit.edu/mailme.html"> ask Andy </A>.
</FONT>
</BODY>
</HTML>
END

sub makeentry {
        $filename = $_[0];

        if ($currentcolumn == 0) {
                print OUTPUT "<TR>\n";
        }
        print OUTPUT "<TD align=\"center\" bgcolor=\"#FFFFFF\"> <A href=\"$filen
ame\"> <IMG src=\"thumbs/$filename\"> <BR> $filename </A> </TD>\n";
        $currentcolumn ++;
        if ($currentcolumn == $maxcols) {
                print OUTPUT "</TR>";
                $currentcolumn = 0;
        }
}

sub makeicon {
        $filename = $_[0];
        if (-s "thumbs/$filename") {
        }
        else {
                $tempfile1 = "/var/tmp/icon.$$1.pnm";
                $tempfile2 = "/var/tmp/icon.$$2.pnm";
                system ("/mit/graphics/arch/pmax_ul4/bin/djpeg -pnm -outfile $te
mpfile1 $filename");
                system ("/mit/graphics/arch/pmax_ul4/bin/pnmscale -ysize 50 $tem
pfile1 > $tempfile2");
                system ("/mit/graphics/arch/pmax_ul4/bin/cjpeg $tempfile2 > thum
bs/$filename");
        }
}

