PHP对图片按照一定比例缩放并生成图片文件

list($width, $height)=getimagesize($filename);
//缩放比例
$per=round(400/$width,3);

$n_w=$width*$per;
$n_h=$height*$per;
$new=imagecreatetruecolor($n_w, $n_h);
$img=imagecreatefromjpeg($filename);
//copy部分图像并调整
imagecopyresized($new, $img,0, 0,0, 0,$n_w, $n_h, $width, $height);
//图像输出新图片、另存为
imagejpeg($new, "a.jpg");
imagedestroy($new);
imagedestroy($img);

posted @ 2016-10-25 11:51  (BACH)  阅读(5811)  评论(0编辑  收藏  举报