php缩小和放大图片(缩放图片)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_41399976/article/details/101432269
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);

猜你喜欢

转载自blog.csdn.net/qq_41399976/article/details/101432269