PHP | imagecrop() Function (original) (raw)

Last Updated : 11 Jul, 2025

The imagecrop() function is an inbuilt function in PHP which is used to crop an image to the given rectangle. This function crops an image to the given rectangular area and returns the resulting image. The given image is not modified.Syntax:

resource imagecrop ( image,image, image,rect )

Parameters: This function accepts two parameters as mentioned above and described below:

Return Value: This function return cropped image resource on success or False on failure. Below programs illustrate the imagecrop() function in PHP:Program:

php `

size=min(imagesx(size = min(imagesx(size=min(imagesx(im), imagesy($im)); // Set the crop image size im2=imagecrop(im2 = imagecrop(im2=imagecrop(im, ['x' => 0, 'y' => 0, 'width' => 250, 'height' => 150]); if ($im2 !== FALSE) { header("Content-type: image/png"); imagepng($im2); imagedestroy($im2); } imagedestroy($im); ?>

`

output: image crop Related Articles:

Reference: https://www.php.net/manual/en/function.imagecrop.php