How can I detect whether an image is a PNG or APNG format?

Posted by perlit on Stack Overflow See other posts from Stack Overflow or by perlit
Published on 2011-01-16T13:46:35Z Indexed on 2011/01/16 13:53 UTC
Read the original article Hit count: 293

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about python