Home >Backend Development >PHP Tutorial >PHP image scaling, _PHP tutorial

PHP image scaling, _PHP tutorial

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

PHP pictures are scaled proportionally,

Create a new file index.php, and there needs to be 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 image, save as
imagejpeg($new, "q1.jpg");
imagedestroy($new);
imagedestroy($img);
?>

After running it with a browser, there will be q1.jpg in the directory at the same level as index.php. This image is a scaled image. The path can be changed in the source code and placed in your own project. You can go or write a method

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1035423.htmlTechArticlePHP pictures are scaled proportionally. Create a new file index.php. There needs to be 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: ?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