PHP | Imagick cropImage() Function
Last Updated :
06 Oct, 2021
The Imagick::cropImage() function is an inbuilt function in PHP which is used to extracts the region of the image.
Syntax:
int Imagick::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 True on success.
Below programs illustrate the Imagick::cropImage() function in PHP:
Original Image:
Program 1:
php
<?php
$image = new Imagick(
$image ->cropImage(390, 100, 0, 0);
header( "Content-Type: image/jpg" );
echo $image ->getImageBlob();
?>
|
Output:
Original Image:
Program 2:
php
<?php
$string = "Computer Science portal for Geeks!" ;
$im = new Imagick();
$draw = new ImagickDraw();
$draw ->setFillColor( new ImagickPixel( 'green' ));
$draw ->setFontSize(50);
$matrix = $im ->queryFontMetrics( $draw , $string );
$draw ->annotation(0, 40, $string );
$im ->newImage( $matrix [ 'textWidth' ], $matrix [ 'textHeight' ],
new ImagickPixel( '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/imagick.cropimage.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...