#!/usr/bin/perl

# Resize the images in <srcdir> to be <xsize> width and <ysize> height
# and put the results in <targetdir>

# Matt Dailey 2000

# Check number of arguments

if (@ARGV != 4) { &usage; }

# Get args

$xsize = $ARGV[0];
$ysize = $ARGV[1];
$srcdir = $ARGV[2];
$targetdir = $ARGV[3];

# Check validity of args

if (!(-d "$srcdir")) {
  print STDERR "<srcdir> does not exist\n";
  &usage;
}
if (!(-d "$targetdir")) {
  print STDERR "<targetdir> does not exist\n";
  &usage;
}
if ($xsize <= 0 || $ysize <= 0) {
  print STDERR "<xsize> or <ysize> out of range\n";
  &usage;
}
if ($srcdir eq $targetdir) {
  print STDERR "don't be silly, I can't do that!\n";
  &usage;
}

# Resize each pgm file in srcdir

@files = glob("$srcdir/*.pgm");

foreach $f (@files) {
  $out = $f; $out =~ s/^.*\///g; $out = "$targetdir/$out";
  print "$f -> $out...\n";
  system("pnmscale -xysize $xsize $ysize < $f > $out");
}

sub usage {
  print STDERR "usage: resize_emo.pl <xsize> <ysize> <srcdir> <targetdir>\n";
  exit -1;
}

