Picture clipping refers to a large background picture cropped out a designated area of the picture, the common application is in the user set personal avatar, can be uploaded from the picture, cut out a suitable area as their personal portrait picture. Image cropping is similar to picture scaling, so it is also accomplished with the help of the imagecopyresampled () function. Also, take the JPEG image format as an example, declaring an image clipping function cut (), as shown in the following code:
Copy Code code as follows:
<?php
To crop a picture in a large background picture, in the JPEG image format, as an example
function Cut ($filename, $x, $y, $width, $height) {
$back = Imagecreatetruecolor ($width, $height);
Create a resource that can save cropped pictures
$cutimg = Imagecreatetruecolor ($width, $height);
To crop a picture using the imagecopyresampled () function
Imagecopyresampled ($cutimg, $back, 0,0, $x, $y, $width, $height, $width, $height);
Save the cropped picture and prefix the cropped picture if you don't want to overwrite the picture
Imagejpeg ($cutimg, $filename);
Imagedestroy ($CUTIMG);
Imagedestroy ($back);
}
Cut ("Brophp.jpg", 50, 50, 200, 200);
?>