【发布时间】:2013-05-27 05:59:32
【问题描述】:
我想要做的是仅将动画 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 循环(它永远不会死)。
不知道我在这里错过了什么。
【问题讨论】:
-
使用
GD库创建 gif 的副本会将 gif 保存为静态图像,因为您需要一个库来调整带框架的大小。 -
你确定 $img 是一个数组吗?如果不是,foreach 不会进入“内部”。
-
另外,你确定它通过了这个断言吗?
-
@Class 我不想使用
GD。使用GD肯定会工作,因为它不支持动画。 @Uberfuzzy 是的,它通过了第一个断言,是的,根据文档,它显然应该是一个数组。
标签: php animated-gif gmagick