PHP 5.4.31 Released

Imagick::cropImage

(PECL imagick 2.0.0)

Imagick::cropImageExtracts a region of the image

Description

bool Imagick::cropImage ( int $width , int $height , int $x , int $y )

Extracts a region of the image.

Parameters

width

The width of the crop

height

The height of the crop

x

The X coordinate of the cropped region's top left corner

y

The Y coordinate of the cropped region's top left corner

Return Values

Returns TRUE on success.

Errors/Exceptions

Throws ImagickException on error.

add a note add a note

User Contributed Notes 3 notes

up
0
Christian Dehning
4 years ago
When cropping gif-images (I had no problems with jpg and png images), the canvas is not removed. Please run the following command on the cropped gif, to remove the blank space:

$im->setImagePage(0, 0, 0, 0);
up
-1
ElPadre
3 years ago
Actually, the Imagick::setImagePage(0,0,0,0) is also handy with jpgs and pngs, if you plan to do any more changes on the cropped image that involves positioning and/or gravity (I created a script that does crop, face blur and watermarking in one go, and had a hell of a time determining why the blurs and the watermark text never showed up...).
up
-5
vincent dot hoen at gmail dot com
6 years ago
There is an easiest way to crop an image : 

$picture = new Imagick('animated_gif.gif');

foreach($picture as $frame){
    $frame->cropImage($width, $height, $x, $y);
}
To Top