Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Image::Magick not printing full image

by jonnyfolk (Vicar)
on Mar 19, 2008 at 18:53 UTC ( #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 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://675064]
Approved by pc88mxer
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2018-06-18 12:13 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (109 votes). Check out past polls.