The Gmagick::cropimage() function is an inbuilt function in PHP which is used to extracts the region of the image. This function crop the part of image.
Syntax:
public Gmagick::cropimage( $width , $height , $x , $y )
Parameters: This function accept four parameters as mention above and describe below.
- $width: This parameter is used to specify the width of the cropped image.
- $height: This parameter is used to specify the height of the cropped image.
- $x: This parameter is used to specify the X coordinate of the cropped image of top left corner.
- $y: This parameter is used to specify the Y coordinate of the cropped image of top left corner.
Return Value: This function returns the cropped Gmagick object.
Below programs illustrate the Gmagick::cropimage() function in PHP:
Original Image 1:

Program 1:
<?php // require_once('path/vendor/autoload.php'); // Create an Gmagick object $image = new Gmagick( // Gmagick function to crop Image $image->cropimage(390, 100, 0, 0); header("Content-Type: image/jpg"); // Display the image echo $image->getImageBlob(); ?> |
Output:
Original Image 2:

Program 2:
<?php $string = "Computer Science portal for Geeks!"; // Creating new image of above String // and add color and background color $im = new Gmagick(); $draw = new GmagickDraw(); // Fill the color in image $draw->setFillColor(new GmagickPixel('green')); // Set the text font size $draw->setFontSize(50); $metrix = $im->queryFontMetrics($draw, $string); $draw->annotation(0, 40, $string); $im->newImage($metrix['textWidth'], $metrix['textHeight'], new GmagickPixel('white')); // Draw the image $im->drawImage($draw); // Set the image format $im->setImageFormat('png'); // Gmagick function to crop Image $im->cropimage(420, 120, 0, 0); header("Content-Type: image/jpg"); // Display the image echo $im->getImageBlob(); ?> |
Output:

Reference: http://php.net/manual/en/gmagick.cropimage.php
Recommended Posts:
- PHP | Imagick cropImage() Function
- PHP | Gmagick getimagecolors() Function
- PHP | Gmagick writeimage() Function
- PHP | Gmagick shearimage() Function
- PHP | Gmagick resizeimage() Function
- PHP | Gmagick rollimage() Function
- PHP | Gmagick getversion() Function
- PHP | Gmagick flopimage() Function
- PHP | Gmagick rotateimage() Function
- PHP | Gmagick scaleimage() Function
- PHP | Gmagick oilpaintimage() Function
- PHP | Gmagick raiseimage() Function
- PHP | Gmagick reducenoiseimage() Function
- PHP | Gmagick solarizeimage() Function
- PHP | Gmagick thumbnailimage() Function
- PHP | Gmagick spreadimage() Function
- PHP | Gmagick stripimage() Function
- PHP | Gmagick swirlimage() Function
- PHP | Gmagick resampleimage() Function
- PHP | Gmagick normalizeimage() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


