PHP | Gmagick cropimage() Function
Last Updated :
28 Aug, 2019
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
$image = new Gmagick(
$image ->cropimage(390, 100, 0, 0);
header( "Content-Type: image/jpg" );
echo $image ->getImageBlob();
?>
|
Output:
Original Image 2:
Program 2:
<?php
$string = "Computer Science portal for Geeks!" ;
$im = new Gmagick();
$draw = new GmagickDraw();
$draw ->setFillColor( new GmagickPixel( 'green' ));
$draw ->setFontSize(50);
$metrix = $im ->queryFontMetrics( $draw , $string );
$draw ->annotation(0, 40, $string );
$im ->newImage( $metrix [ 'textWidth' ], $metrix [ 'textHeight' ],
new GmagickPixel( 'white' ));
$im ->drawImage( $draw );
$im ->setImageFormat( 'png' );
$im ->cropimage(420, 120, 0, 0);
header( "Content-Type: image/jpg" );
echo $im ->getImageBlob();
?>
|
Output:
Reference: http://php.net/manual/en/gmagick.cropimage.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...