我想做的是只保存在静态图像(非动画gif)的动画GIF的第一帧。
使用Gmagick 1.1.2RC1和GraphicMagick 3.1.18
我读了很多关于它的帖子。有人说它可以在以前版本的Gmagick中工作,但在新版本中就不行了。
以下是我当前的测试代码:
public function testAnimatedGifFrame()
{
$testAnimGif = $this->assets.'/animated.gif';
$im = new \Gmagick($testAnimGif);
$frameNumber = $im->getNumberImages();
$this->assertEquals(47, $frameNumber, 'The number of frame for the animated GIF should be 47');
// Select the first frame and save it
$frameIndex = 0;
$img = $im->coalesceImages();
foreach ($img as $frame) {
die('here');
$frameName = ++$frameIndex . '.gif';
$frame->writeImage( $frameName );
}
}动画GIF由47帧组成,但是当使用coalesceImages()时,脚本永远不会进入foreach循环(它永远不会死)。
不知道我错过了什么。
发布于 2013-05-28 14:12:45
对于那些想要像我一样使用Imagick或Gmagick的人。
只需将其保存为JPG和BAM!
public function testAnimatedGifFrame()
{
$testAnimGif = $this->assets.'/animated.gif';
$singleFrame = $this->assets.'/test_single_frame.jpg';
$im = new \Gmagick($testAnimGif);
$frameNumber = $im->getNumberImages();
$this->assertEquals(47, $frameNumber, 'The number of frame for the animated GIF should be 47');
// Save the image as JPG to disable the animation
$im->setImageFormat('JPG');
$im->writeImage($singleFrame);
$im->destroy();
}如果你想保存动画的最后一张图片,而不是第一张,你只需要在$im->setImageFormat('JPG');之前添加$im = $im->flattenImages();
我希望这会对你们中的一些人有所帮助;)
https://stackoverflow.com/questions/16767132
复制相似问题