Home > Backend Development > PHP Tutorial > PHP image processing: Example of cropping images using imagecopyresampled function, _PHP tutorial

PHP image processing: Example of cropping images using imagecopyresampled function, _PHP tutorial

WBOY
Release: 2016-07-13 10:13:42
Original
873 people have browsed it

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);
?>

www.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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template