After spending a while trying to optimize things, I ended up with an average time of around 6.5 seconds, which is much better than the initial 10 seconds.
I am now resizing the animation outside the loop and using optimizeImageLayers
which is faster than deconstructImages
and also keeps the filesize down.
$image = new Imagick('myfile.gif');
$image = $image->coalesceimages();
$final = new \Imagick();
foreach ($image as $frame){
$image->thumbnailImage($width, $height, true);
$geometry = $image->getImageGeometry();
$x = ( $width - $geometry['width'] ) / 2;
$y = ( $height - $geometry['height'] ) / 2;
$canvas = new \Imagick();
$canvas->newImage( $width, $height, $background);
$canvas->compositeImage( $image, \Imagick::COMPOSITE_OVER, $x, $y );
$final->addimage($canvas);
}
$final = $final->optimizedImageLayers();
$final->writeImages('resized.gif', true);
This is currently what I am using and am quite happy with it. However, I am will be looking at tweaking imagemagick's settings and playing with the color depth, etc to make it better, once I find some spare time of course :)