加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 13:39:02 所属栏目:PHP教程 来源:网络整理
导读:我有PNG(以及JPEG)图像上传到我的网站. 它们应该是静态的(即一个框架). 有这样的事情就是APNG. (它将在Firefox中动画). 根据Wikipedia article … APNG hides the subsequent frames in PNG ancillary chunks in such a way that APNG-unaware applications
我有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;
    }
?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读