Home > Backend Development > PHP Tutorial > php实现图片等比例缩放代码_PHP

php实现图片等比例缩放代码_PHP

WBOY
Release: 2016-05-30 08:46:24
Original
861 people have browsed it

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

源代码如下:

<&#63;php
$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);
&#63;>

Copy after login

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

以上所述上就是本文的全部内容了,希望对大家学习php语言能够有所帮助。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template