An example of using the imagecopyresampled function to crop images in PHP image processing,
Image cropping refers to cutting out a picture of a specified area from a large background picture. A common application is when users set their personal avatar, they can cut out a suitable area from the uploaded picture as their own Profile picture. Image cropping is similar to image scaling, so the imagecopyresampled() function is also used to implement this function. Also taking the JPEG image format as an example, declare an image cropping function cut(). The code is as follows:
Copy code The code is as follows:
//Crop out a picture in a specified area from a large background picture, taking the jpeg picture format as an example
Function cut($filename,$x,$y,$width,$height){
$back = imagecreatetruecolor($width, $height);
//Create a resource that can save the cropped image
$cutimg = imagecreatetruecolor($width, $height);
//Use the imagecopyresampled() function to crop the image
Imagecopyresampled($cutimg,$back,0,0,$x,$y,$width,$height,$width,$height);
//Save the cropped picture. If you don’t want to overwrite the picture, you can add a prefix to the cropped picture
Imagejpeg($cutimg,$filename);
Imagedestroy($cutimg);
Imagedestroy($back);
}
cut("brophp.jpg", 50, 50, 200, 200);
?>
http://www.bkjia.com/PHPjc/914053.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/914053.htmlTechArticlePHP image processing example of using the imagecopyresampled function to crop images. Image cropping refers to cropping out a large background image. A picture of a designated area, a common application is when the user...