在PHP中读取动画GIF [英] Reading animated GIF in PHP

查看:244
本文介绍了在PHP中读取动画GIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要阅读PHP中动画GIF的各个帧.

I am in need of reading the individual frames of an animated GIF in PHP.

我一直使用GD进行图像处理,但不幸的是,它缺乏处理GIF图像中多个帧的功能.

I use GD all the time for image manipulation, but unfortunately it lacks the capability to handle multiple frames in a GIF image.

我目前正在尝试制作GIF文件格式,以尝试制作自己的提取器,但是在进一步研究之前,我想知道是否有人对已经执行此操作的代码有任何指针-我可以当然,它是第一个想要用PHP处理动画的人.

I'm currently in the middle of carving up the GIF file format in an attempt to make my own extractor, but before I go any further I was wondering if anyone had any pointers for code that already does this - I can't be the first to want to handle animations in PHP, surely.

推荐答案

是的.我认为ImageMagick扩展在您的情况下应该可以很好地工作.我以前在PHP代码中使用过它,虽然以前没有使用过GD,但ImageMagick足以满足我的次要图像处理需求. =)

Yup. I think the ImageMagick extension should work nicely in your case. I've used it in my PHP codes before, and while I've not used GD before, ImageMagick has been sufficient for my minor image manipulation needs. =)

$agif = new Imagick("animated.gif");

// Loop over all individual frames 
foreach ($agif as $frame) {

    // Do whatever you need to do here 

}

// Save the modified gif
$agif->writeImages("new_animated.gif", true);

可以通过 http:/找到可通过ImageMagick PHP扩展使用的全部功能./php.net/manual/en/book.imagick.php

这篇关于在PHP中读取动画GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆