I have a script for an 'article manager' web-based interface, where the manager uploads a given image to the server.

Before writing the image to the server, which is to be embedded into the article it is associated with, its width and height are checked:

use Image::Magick; ... # Check and change image height if necessary my ($height,$width); ($height,$width) = $image->GetAttribute('height','width'); if ( $height > 300 ) { my ($newheight,$newwidth); $newheight = 300; $newwidth = ($width*$newheight)/$height; $image->Scale('height'=>$newheight,'width'=>$newwidth); } # Check and change image width if necessary ($height,$width) = $image->GetAttribute('height','width'); if ( $width > 250 ) { my ($newheight,$newwidth); $newwidth = 250; $newheight = ($height*$newwidth)/$width; $image->Scale('width'=>$newwidth,'height'=>$newheight); }

No problem with that code (save it being repetitive in parts, which is necessary as I need to have verbose code for the client, not necessarily 'clean, Perlish' code).

However, I also need to check/change image resolution, which from my understanding should be able to be done like so:

# Adjust Resolution if necessary $image->SetAttribute('units'=>'PixelsPerInch'); my ($xrez,$yrez) = $image->GetAttribute('x-resolution', 'y-resolution'); if ($xrez > 72 || $yrez > 72) { $image->SetAttribute('density'=>'72x72'); }
But alas, the image is written to the server in the following steps with the initial resolution, which could be above 72 and is undesirable.

Embedding print statements before the resolution block of code yields, say for an example image:

x-resolution is 300 y-resolution is 300

After the resolution block, the same print statement yields:

x-resolution is 72 y-resolution is 72

Which would lead one to believe the transformation occurred, although it did not (the image on the server retains the original resolution).

Have any fellow monks run into such problems before?

--
notsoevil
--
Jeremiah 49:32 - And their camels shall be a booty. . .


In reply to Changing Image Resolution by notsoevil

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.