Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: shrink.pl - Scales down images

by merlyn (Sage)
on Jan 22, 2001 at 00:59 UTC ( #53375=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://53375]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-04-21 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?