in reply to shrink.pl - Scales down images

Boy, are you gonna be surprised to find out that you can replace most of your logic with...
... main code ... $size = "${size}x$size" unless $size =~ /%$/; ... sub shrink { my $name = shift; my $img = Image::Magick->new; $img->Read($name); $img->Mogrify('geometry' => $size); $img->Write($name); }
And then let $size be either "50%" or "72" at the top there. The former will make a half-size picture. The latter will make the largest image that fits into 72x72, while keeping the proportions, as all your code attempts to do.

Yeah, the ImageMagick docs are a real pain to get into, but once you've got the good tricks, it's rather nice.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: shrink.pl - Scales down images
by Vortacist (Pilgrim) on Jan 22, 2001 at 01:51 UTC
    I appreciate the help, and have updated my code accordingly. I would like to mention, though, that I don't think you can use Mogrify in:

    $img->Mogrify('geometry' => $size);

    You have to use Resize in order to get it to work...or at least I did.