使用 imagick 将调整大小的动画 gif 输出到浏览器
我打算调整 gif 动画的大小并将其即时输出到浏览器。我的问题是,当我保存调整大小的图像时,它的质量很好,但如果我回显
它到浏览器,它的质量很差并且动画被删除。这是代码:
header("Content-type:image/gif");
try
{
/*** Read in the animated gif ***/
$animation = new Imagick("images/nikks.gif");
/*** Loop through the frames ***/
foreach ($animation as $frame)
{
/*** Thumbnail each frame ***/
$frame->thumbnailImage(200, 200);
/*** Set virtual canvas size to 100x100 ***/
$frame->setImagePage(200, 200, 0, 0);
}
/*** Write image to disk. Notice writeImages instead of writeImage ***/
//$animation->writeImages("images/nikkyo1.gif",true);
echo $animation;
}
catch(Exception $e)
{
echo $e->getMessage();
}
I intend to resize an animated gif and output it to the browser on-the-fly. My problem is that when I save the resized image, it is of good quality, but if I echo
it to the browser, it is of poor quality and the animation is removed. Here is the code:
header("Content-type:image/gif");
try
{
/*** Read in the animated gif ***/
$animation = new Imagick("images/nikks.gif");
/*** Loop through the frames ***/
foreach ($animation as $frame)
{
/*** Thumbnail each frame ***/
$frame->thumbnailImage(200, 200);
/*** Set virtual canvas size to 100x100 ***/
$frame->setImagePage(200, 200, 0, 0);
}
/*** Write image to disk. Notice writeImages instead of writeImage ***/
//$animation->writeImages("images/nikkyo1.gif",true);
echo $animation;
}
catch(Exception $e)
{
echo $e->getMessage();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下
try it with