my ($width, $height ) = ...; my ($max_width, $max_height ) = (800, 600); my ($width_factor, $height_factor) = ($max_width/$width, $max_height/$height); if ($width_factor < 1 || $height_factor < 1) { my $factor = ($width_factor < $height_factor ? $width_factor : $height_factor ); $width = int($width * $factor + 0.5); $height = int($height * $factor + 0.5); } #### use Image::Magick qw(); my $img = Image::Magick->new(); my $file_name = ...; my $img->Read($file_name); my ($width, $height ) = $img->Get(qw( width height )); my ($max_width, $max_height ) = (800, 600); my ($width_factor, $height_factor) = ($max_width/$width, $max_height/$height); if ($width_factor < 1 || $height_factor < 1) { my $factor = ($width_factor < $height_factor ? $width_factor : $height_factor ); my $new_width = int($width * $factor + 0.5); my $new_height = int($height * $factor + 0.5); $img->Resize(width => $new_width, height => $new_height); $img->Write($file_name); }