notsoevil has asked for the wisdom of the Perl Monks concerning the following question:
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:
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.# 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'); }
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. . .
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Changing Image Resolution
by merlyn (Sage) on Apr 28, 2001 at 04:24 UTC | |
by notsoevil (Pilgrim) on Apr 28, 2001 at 06:57 UTC |