Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

In reply to Re: Manipulating Images (height and width) by OeufMayo
in thread Manipulating Images (height and width) by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-03-19 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found