#!/usr/bin/perl

use Image::Magick;

my ($image);
my $filename = shift || exit(0);
my $append = shift || "";
my $max_height = shift || 200;

if ($append eq "---") { $append = ""; }

my $base = '/var/home/slowtwitch/slowtwitch.com/www/tick/images/gallery';
my $new_filename = "${base}/${append}${filename}";

$image = Image::Magick->new;
$image->Read("${base}/${filename}");

$width = $image->Get('columns');
$height = $image->Get('rows');

if (($width > 900) || ($height > $max_height))
{
    $image->Resize(geometry=>"${width}x${max_height}");
    # $image->Scale(geometry=>"${longest_side}x${longest_side}");
    # $image->Border(geometry=>'5x5');
    $image->Write(filename=>"${new_filename}", quality=>'75');
}

undef $image;
exit(0);
