Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Image::Magick not printing full image

by jonnyfolk (Vicar)
on Mar 19, 2008 at 18:53 UTC ( [id://675064]=perlquestion: print w/replies, xml ) Need Help??

jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:

The following is an exerpt from a larger script. I am reducing all photos down to a set width for thumbnail viewing. Each of the photos is read using cgi.pm param() and put into array @photos. I am getting the expected images in the right places, but varying portions of the image are lost at the end of the file, showing as grey pixels.(ranging from half the bottom row to 3 or 4 bottom rows). I added the sprintf line in case decimals were messing it up, but it didn't change anything. Is there anything in the following code which might be causing this? Thanks for any help.
my $photofiletmp; foreach my $item (@photos) { $countphotos++; $photofiletmp = $dirphoto . '/' . 'photo' . $countphotos . '.tmp'; if ($item) { open SAVE, '>', $photofiletmp or die $!; while (<$item>) { print SAVE $_; } my($image, $x); $image = Image::Magick->new; $x = $image->Read($photofiletmp); my ($ox,$oy) = $image ->Get('width','height'); my $r = ($oy * 180) / $ox; $r = sprintf ( "%d", $r ); $x = $image->Resize(width=>180,height=>$r); my $photofile = $dirphoto . '/' . 'photo' . $countphotos . '.jpg +'; $x = $image->Write("$photofile"); unlink $photofiletmp; } }

Replies are listed 'Best First'.
Re: Image::Magick not printing full image
by pc88mxer (Vicar) on Mar 19, 2008 at 19:08 UTC
    Try adding a close(SAVE) after the while loop. I bet the last bit of data is not getting flushed out to the tmp file before you access it again with Image::Magick.
      And that just got me 4 perfect images! Thanks very much for your help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://675064]
Approved by pc88mxer
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-24 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found