#!/usr/bin/perl

use strict;

my ($file, $results, $num_cols);
my ($d_height, $d_width, $r_height, $r_width);
open (OUTFILE, ">index.html");
opendir (CURDIR, ".");

print (OUTFILE "<html>\n");
print (OUTFILE "<br><b>Current images:</b>\n");
print (OUTFILE "<table>\n");
print (OUTFILE "<tr>\n");
$num_cols = 0;
foreach $file (readdir (CURDIR))
{
  next if $file =~ /^tiny.*/;
  if ($file =~ /(\.jpg)|(\.gif)/)
  {
    $results = `identify $file`;
    $results =~ m/(\d+)x(\d+)/;
    $r_width = $1;
    $r_height = $2;
    $d_height = 120;   # An arbitrary height
    $d_width  = int ($d_height * $r_width/$r_height);
    `cp $file tiny.${file}`;
    `mogrify -geometry ${d_width}x${d_height} tiny.${file}`;
    print ("Processing $file\n");
    print ("  Command: mogrify -geometry ${d_width}x${d_height} tiny.${file}\n");
    print (OUTFILE "    <td>\n");
    print (OUTFILE "        <a href=\"/current/vladi2/$file\">");
    print (OUTFILE "<img src=\"/current/vladi2/tiny.$file\"></a>\n");
    print (OUTFILE "    </td>\n");
  }
  $num_cols++;
  if ($num_cols % 5 == 0)
  {
    print (OUTFILE "</tr>\n");
    print (OUTFILE "\n<tr>\n");
  }
}
  if ($num_cols % 5 != 0)
  {
    print (OUTFILE "</tr>\n");
  }
print (OUTFILE "</table>\n");
