I've read some SOPWs on this question and someone said as long as you pass the max HEIGHT or max WIDTH to the browser, the other size will automatically be resized.

I'm trying to make sure my images are less than max_h and max_w, if they are I want them both resized so they're the same aspect ratio but under my requirements.

I tried the below and I'm guessing my problem lies in it only checks one side, not both. So if BOTH sides are too big, only one is resized leaving the other one POSSIBLY too big.

Can someone help me?

############################## # Image Resize ############################## use Image::Info qw(image_info dim); my $img_info = image_info("pictures/$pic_id.jpg"); my ($height, $width) = dim($img_info); my ($max_width, $max_height ) = (600,800); if ($height >= $max_height) { print qq(<center><a href="http://www.site.com/viewer2.cgi?id=$pic_i +d" target="new"><img src="$img_src" height="800" border="0"></href></ +center>); } elsif ($width >= $max_width) { print qq(<center><a href="http://www.site.com/viewer2.cgi?id=$pic_i +d" target="new"><img src="$img_src" width="600" border="0"></a></cent +er>); } else { print qq(<center><a href="http://www.site.com/viewer2.cgi?id=$pic_i +d" target="new"><img src="$img_src" border="0"></a></center>); }

In reply to Can't automaticaly HTML-resize my images 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":



  • 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.