I had the same problem as you, and I found that the solution uses the coalesceimages function.
Here is a working example for cropping and resizing an animated gif in php using Imagick:
<?php
if($width > $height) {
$x = ceil(($width - $height) / 2 );
$width = $height;
} elseif($height > $width) {
$y = ceil(($height - $width) / 2);
$height = $width;
}
$image = new Imagick(HERE_YOU_PUT_BIG_IMAGE_PATH);
$image = $image->coalesceImages();
foreach ($image as $frame) {
$frame->cropImage($width, $height, $x, $y);
$frame->setImagePage(0, 0, 0, 0);
}
$image = $image->coalesceImages();
foreach ($image as $frame) {
$frame->resizeImage($newWidth, $newHeight,Imagick::FILTER_LANCZOS,1);
}
$image->writeImages(CROPPED_AND_RESIZED_IMAGE_PATH_HERE, true);
?>
.
, .
, $frame- > cropImage ($ width, $height, $x, $y); , .
IE $frame- > cropImage ($ s ['params'] ['w'], $s ['params'] ['h'], $s ['params'] ['x'], $ [ 'PARAMS'] [ '']);
, , :
$image = new Imagick(HERE_YOU_PUT_BIG_IMAGE_PATH);
$image = $image->coalesceImages();
foreach ($image as $frame) {
$frame->cropImage($s['params']['w'], $s['params']['h'], $s['params']['x'], $s['params']['y']);
$frame->setImagePage(0, 0, 0, 0);
}
, !
Ps: :)