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.