Home >Backend Development >PHP Tutorial >PHP code to implement image scaling, _PHP tutorial
Create a new file index.php, you need to have a picture in the statistics directory as q.jpg (the name of the picture can be changed according to the source code )
The source code is as follows:
<?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); ?>
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
The above is the entire content of this article. I hope it will be helpful to everyone learning the PHP language.