有没有办法用 PHP 或 Java 检查 GIF 图像是否有动画?
您知道 GIF 文件支持动画,但 GIF 图像不一定必须有动画。
有没有办法使用 php 或 java 检查 GIF 图像是否有动画?
谢谢。
You know that GIF files support animation, but a GIF image not necesarily must have an animation on it.
Is there a way to check if a GIF image has an animation using php or java?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里有一个 PHP 脚本,应该能够确定图像是否是 gif 动画。我已经测试过它并且它对我有用。
只需将 $img 变量编辑为您想要测试的任何图像(例如 image.gif、image.jpg)。
Here is a little PHP script that should be able to determine if an image is an animated gif or not. I have tested it and it works for me.
Simply edit the $img variable to whatever image you want to test (e.g. image.gif, image.jpg).
imagecreatefromgif() 函数的 php 手册页中有一段简短的代码片段,它应该是您所需要的:
如果您需要,可以很容易地对其进行修改以计算帧数。
参见此处
There is a brief snippet of code in the php manual page of the imagecreatefromgif() functions the should be what you need:
It could quite easily be modified to count the number of frames if you required.
See Here
尝试这样的事情:
如果它返回 1,则它不是动画的。
我会谨慎地在不依赖像 Imagick 这样的库的情况下编写函数,因为像 这个。
Try something like this:
If it returns 1, it's not animated.
I'd be wary of coding a function without relying on a library like Imagick because of "gotchas" like this.