有没有一种方法可以检查GIF图像是否具有PHP或Java动画? [英] Is there a way to check if a GIF image has animation with PHP or Java?
本文介绍了有没有一种方法可以检查GIF图像是否具有PHP或Java动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您知道GIF文件支持动画,但是GIF图像不一定必须在其上具有动画.
You know that GIF files support animation, but a GIF image not necesarily must have an animation on it.
是否可以使用php或java检查GIF图像是否具有动画?
Is there a way to check if a GIF image has an animation using php or java?
谢谢.
推荐答案
下面是一个小的PHP脚本,它可以确定图像是否为动画gif.我已经对其进行了测试,并且对我有用.
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.
<?php
$img="your_image";
$file = file_get_contents($img);
$animated=preg_match('#(\x00\x21\xF9\x04.{4}\x00\x2C.*){2,}#s', $file);
if ($animated==1){
echo "This image is an animated gif";
} else {
echo "This image is not an animated gif";
}
?>
只需将$ img变量编辑为要测试的任何图像(例如image.gif,image.jpg).
Simply edit the $img variable to whatever image you want to test (e.g. image.gif, image.jpg).
这篇关于有没有一种方法可以检查GIF图像是否具有PHP或Java动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文