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);
}
Imagick::cropImage
(PECL imagick 2.0.0)
Imagick::cropImage — 画像の一部を抽出する
説明
bool Imagick::cropImage
( int $width
, int $height
, int $x
, int $y
)
警告
この関数は、 現在のところ詳細な情報はありません。引数のリストのみが 記述されています。
画像の一部を抽出します。
パラメータ
- width
-
抽出する幅。
- height
-
抽出する高さ。
- x
-
抽出する領域の左上の X 座標。
- y
-
抽出する領域の左上の Y 座標。
返り値
成功した場合に TRUE を返します。
エラー / 例外
エラー時に ImagickException をスローします。
Imagick::cropImage
vincent dot hoen at gmail dot com
02-Aug-2007 01:35
02-Aug-2007 01:35
vincent dot hoen at gmail dot com
01-Aug-2007 03:39
01-Aug-2007 03:39
If you're working with animated gif you might want to process this way (Probably not the best, but at least it works) :
$picture = new Imagick('animated_gif.gif');
//Crop first image
$picture->cropImage($width, $height, $x, $y);
//Crop every other image
while($picture->hasNextImage()){
$this->nextImage();
$this->cropImage($width, $height, $x, $y);
}
//display image
$picture->getImageBlob();
