I wrote this for an online image gallery. I wanted the 'long' dimension to be no larger than 450 pixels, so my script needed to do the resizing before commiting the file to disk and I needed to write down the height and width attributes so that I could modify the HTML to display the image correctly. Here's my code:

# write the file to a temporary location my $tmp_loc = $TEMP_IMG_DIR . $image_name; my $whan; open($whan,">$tmp_loc") || die "Cannot write $tmp_loc $!"; print $whan $temp_file_var; close($whan); # Resize image and write it to the appropriate location use Image::Thumbnail; my $t = new Image::Thumbnail( size => 450, create => 1, inputpath => $tmp_loc, outputpath => $main_loc ); # Get the new size of the main image use Image::Info qw(image_info dim); my $info = image_info($main_loc); my ($w, $h) = dim($info);
$temp_file_var is holding the image.
At the end, the new image is written to the path in $main_loc and I have the width $w and the height $h of the new image.

I hope that you can modify this for your use!

oakbox


In reply to Re: Resize image width & height... by oakbox
in thread Resize image width & height... by kiat

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.