3

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

APNG is backwards compatible with PNG. I opened up an apng and png file in a hex editor and the first few bytes look identical. So if a user uploads either of these formats, how do I detect what the format really is? I've seen this done on some sites that block apng.

I'm guessing the ImageMagick library makes this easy, but what if I were to do the detect without the use of an image processing library (for learning purposes)? Can I look for specific bytes that tell me if the file is apng?

Solutions in any language is welcome.

Community
  • 1
  • 1
perlit
  • 329
  • 4
  • 13
  • 2
    possible duplicate of [Can I programatically determine if a PNG is animated?](http://stackoverflow.com/questions/4525152/can-i-programatically-determine-if-a-png-is-animated), solution given is in PHP. – BoltClock Jan 16 '11 at 13:49

4 Answers4

1

From 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"

martineau
  • 119,623
  • 25
  • 170
  • 301
1

See the solution of Can I programatically determine if a PNG is animated?: you could search for the string "acTL".

Community
  • 1
  • 1
Jasmijn
  • 9,370
  • 2
  • 29
  • 43
0

APNG and PNG files' first few bytes' control can be bypass, easily . So this method isn't secure. User can change file's hex code and pass your this control.

Eray
  • 7,038
  • 16
  • 70
  • 120
0

You can use libmagic which is already installed on most Unix platforms.

Sylvain
  • 1,553
  • 11
  • 15