如何检测图像是PNG格式还是APNG格式?

2024-05-12 22:04:41 发布

您现在位置:Python中文网/ 问答频道 /正文

Possible Duplicate:
Can I programatically determine if a PNG is animated?

APNG向后兼容PNG。我在十六进制编辑器中打开了一个apng和png文件,前几个字节看起来完全相同。因此,如果用户上传了这些格式中的任何一种,我如何检测真正的格式呢?我在一些阻止apng的网站上看到过这种做法。在

我猜ImageMagick库使这变得容易,但是如果我在不使用图像处理库(用于学习目的)的情况下进行检测呢?我可以寻找特定的字节来告诉我文件是否是apng吗?在

任何语言的解决方案都是受欢迎的。在


Tags: 文件if字节pngis格式编辑器can
3条回答

请参阅Can I programatically determine if a PNG is animated?的解决方案:可以搜索字符串“acTL”。在

来自http://en.wikipedia.org/wiki/Apng

Among users and maintainers of the PNG and MNG formats, APNG was not well received. In particular, PNG was conceived to be a single-image format [2]. 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. [italics mine]

[2] "PNG (Portable Network Graphics) Specification, Version 1.1#8.4. Multiple-image extension"

APNG和PNG文件的“前几个字节”控制可以轻松绕过。所以这个方法不安全。用户可以更改文件的十六进制代码并传递此控件。在

相关问题 更多 >