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

查看:23
本文介绍了用 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://php.net/manual/en/book.imagick.php

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

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