Home > Backend Development > PHP Tutorial > PHP image scaling

PHP image scaling

WBOY
Release: 2016-08-08 09:20:25
Original
1103 people have browsed it

Create a new file index.php. You need to have a picture q.jpg in the statistics directory (the name of the picture can be changed according to the source code)

The source code is as follows:

$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);
//Copy part of the image and adjust it
imagecopyresized($new, $img,0, 0,0, 0,$n_w, $n_h, $width, $height);
//Image output new picture, save as
imagejpeg($new, "q1.jpg");
imagedestroy($new);
imagedestroy($img);
?>

Use browser After running, there will be a q1.jpg in the directory at the same level as index.php. This picture is a scaled picture. The path can be changed in the source code by yourself, put it in your own project or write a method. OK

The above introduces the proportional scaling of PHP images, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

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