且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有没有一种方法可以检查GIF图像是否具有PHP或Java动画?

更新时间:2023-02-19 23:24:14

下面是一个小的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).