#!/usr/bin/perl

#$psxorig=61.5;
$psxorig=53.5;
#$psyorig=8.4;
$psyorig=5.4;
$psscale=882;

@widths=(500,100);

$htmlpath="./";

open (M, $htmlpath."minimaps.txt") or die "Couldn't open minimaps file: $!";

while(<M>) {
  ($region,$fullname,$e1,$n1,$e2,$n2)=split(/,/);
  $llx=(($e1<$e2 ? $e1 : $e2)/$psscale-$psxorig)/72;
  $lly=(($n1<$n2 ? $n1 : $n2)/$psscale-$psyorig)/72;
  $urx=(($e1>$e2 ? $e1 : $e2)/$psscale-$psxorig)/72;
  $ury=(($n1>$n2 ? $n1 : $n2)/$psscale-$psyorig)/72;

  foreach $width (@widths) {
    system(qq{pstopnm -portrait -xborder 0 -yborder 0 -ysize $width -llx $llx -lly $lly -urx $urx -ury $ury -stdout $htmlpath"outline.eps" > $htmlpath"maps/$region.$width.ppm"});
    system(qq{convert $htmlpath"maps/$region.$width.ppm" $htmlpath"maps/$region.$width.png"});
  }
}
