http://www.perlmonks.org?node_id=675064

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; } }