$width = 100; $height = 75; list($width_orig, $height_orig) = getimagesize($target_path.$file2); if ($width && ($width_orig < $height_orig)) { $width = ($height / $height_orig) * $width_orig; } else { $height = ($width / $width_orig) * $height_orig; }