我有PNG(以及JPEG)图像上传到我的网站.
它们应该是静态的(即一个框架).
有这样的事情就是APNG.
(它将在Firefox中动画).
@H_502_9@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;
- }
- ?>