微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 我可以编程确定一个PNG是否动画?

我有PNG(以及JPEG)图像上传到我的网站.

它们应该是静态的(即一个框架).

有这样的事情就是APNG.

(它将在Firefox中动画).

根据Wikipedia article

APNG hides the subsequent frames in PNG ancillary chunks in such a way that APNG-unaware applications would ignore them,but there are otherwise no changes to the format to allow software to distinguish between animated and non-animated images.

这是否意味着不可能确定PNG是否用代码动画?

如果可以的话,请指点我明智的方向(GD,ImageMagick)吗?

APNG图像被设计为“伪装”为不支持它们的读者的PNG.也就是说,如果读者不支持它们,它只会认为它是一个普通的PNG文件,只显示第一帧.这意味着它们具有与PNG(image / png)相同的MIME类型,它们具有相同的魔术数字(89 50 4e 47 0d 0a 1a 0a),通常它们以相同的扩展名保存(尽管不是真的检查文件类型的好方法).

那么,你如何区分他们呢?
APNG在其中有一个“acTL”块.因此,如果搜索字符串acTL(或十六进制,61 63 54 4C(块标记之前的4个字节(即00 00 00 08))是大字节格式的块的大小,而不计算大小,标记,或在字段的末尾的CRC32))你应该相当不错.为了获得更好的效果,请检查这个块是否在第一次出现“IDAT”块之前出现(只是查找IDAT).

这段代码(从http://foone.org/apng/identify_apng.php开始)将会做到:

<?PHP
# Identifies APNGs
# Written by Coda,functionified by Foone/Popcorn Mariachi#!9i78bPeIxI
# This code is in the public domain
# identify_apng returns:
# true if the file is an APNG
# false if it is any other sort of file (it is not checked for PNG validity)
# takes on argument,a filename.
function identify_apng($filename)
    {
    $img_bytes = file_get_contents($filename);
    if ($img_bytes)
        {
        if(strpos(substr($img_bytes,strpos($img_bytes,'IDAT')),'acTL')!==false)
            {
        return true;
        }
        }
    return false;
    }
?>

原文地址:https://www.jb51.cc/php/138168.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐