use strict;
use warnings;
use Image::Magick;

use constant X_SIZE => 100;
use constant Y_SIZE => 150;

sub do_file
  {
  my $file = shift;	
  my $image = Image::Magick->new();
  my $status = $image->Read($file);
  die "Oops: $status\n" if ($status);

  # Bildmaße bestimmen, Skalierungsfaktor
  my ($width, $height) = $image->Get('width', 'height');

  my $x_scale = X_SIZE/$width;
  my $y_scale = Y_SIZE/$height;
  my $scale = ($y_scale > $x_scale)? $x_scale : $y_scale;
    
  my $x = int($width  * $scale + 0.5);
  my $y = int($height * $scale + 0.5);

  $status = $image->Scale(width => $x, height => $y);
  die "Oops: $status\n" if ($status);
  $status = $image->Write("Thumb/$file");
  die "Oops: $status\n" if ($status);
  }

mkdir("Thumb") if (! -d "Thumb");

foreach my $file (@ARGV)
  { do_file($file); }


