$max_w || $im_height>$max_h) { if ($im_width>$im_height) { // horizontal $scale=($max_w/$im_width); } else { $scale=($max_h/$im_height); // vertical } $new_width = floor($scale*$im_width); $new_height = floor($scale*$im_height); $imNew = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($imNew, $im, 0, 0, 0, 0, $new_width, $new_height, $im_width, $im_height); header("Content-type: image/jpeg"); header( "Content-Disposition: attachment; filename=".$imgFile); header( "Content-Description: PHP Generated Image" ); imagejpeg($imNew,null,80); // cleanup imagedestroy($im); imagedestroy($imNew); } else { header("Content-type: image/jpeg"); header( "Content-Disposition: attachment; filename=".$imgFile ); header( "Content-Description: PHP Generated Image" ); imagejpeg($im); // cleanup imagedestroy($im); } } ?>