Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Manipulating Images (height and width)

by OeufMayo (Curate)
on Sep 09, 2002 at 06:17 UTC ( #196177=note: print w/ replies, xml ) Need Help??


in reply to Manipulating Images (height and width)

You can also use Imager, which is far more easier to install than ImageMagick, has most of the features you will use 90% of the time, and is also easier to use, IMO.

The scale() method allows you to resize image with a maximum height or width. Or if it is not exactly what you want to do, you can still do maths with the getheight() and getwidth() methods.

#!/usr/bin/perl -w use strict; use Imager; my $image = Imager->new; # Load the original image $image->open(file => $ARGV[0]) or die $image->errstr; # Get the dimensions of the picture print "Size: ", $image->getwidth, 'x', $image->getheight, "\n"; # Scale the picture to at most 150px in width or height my $resized = $image->scale( width => 150, height => 150, type => 'min +' ); # Save the resized picture to disk $resized->write(file=>"tn_$ARGV[0]") or die $resized->errstr; __END__
-- 
briac


Comment on Re: Manipulating Images (height and width)
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://196177]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-09-02 23:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (33 votes), past polls