Home  >  Article  >  Backend Development  >  php图片等比例缩放,_PHP教程

php图片等比例缩放,_PHP教程

WBOY
WBOYOriginal
2016-07-13 09:46:201051browse

php图片等比例缩放,

新建文件index.php,需要在统计目录下有个图片为q.jpg(可根据源码进行更改图片的名称)

源代码如下:

$filename="q.jpg";
$per=0.3;
list($width, $height)=getimagesize($filename);
$n_w=$width*$per;
$n_h=$height*$per;
$new=imagecreatetruecolor($n_w, $n_h);
$img=imagecreatefromjpeg($filename);
//拷贝部分图像并调整
imagecopyresized($new, $img,0, 0,0, 0,$n_w, $n_h, $width, $height);
//图像输出新图片、另存为
imagejpeg($new, "q1.jpg");
imagedestroy($new);
imagedestroy($img);
?>

使用浏览器运行过后,在index.php同级的目录下会有个q1.jpg,这个图片就是等比例缩放后的图片,路径可以自己在源代码里面更改,放在自己的项目当中去或写个方法也行

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1035423.htmlTechArticlephp图片等比例缩放, 新建文件index.php,需要在统计目录下有个图片为q.jpg(可根据源码进行更改图片的名称) 源代码如下: ?php $filename="q....
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn