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