pythonapng

How do i detect APNG in python?


APNG files dont have any clear way to detect them. For APNg unawware applications they appear as normal PNGs, and they will show the first screen. Detecting them is a bit of a hassle.


Solution

  • APNGs can be detected by seeing if the data contains a acTL block before a IDAT block.

    this solution is adapted to python from this response: https://stackoverflow.com/a/4525194/5997749

    def is_apng(a: bytes):
        acTL = a.find(b"\x61\x63\x54\x4C")
        if acTL > 0: # find returns -1 if it cant find anything
            iDAT = a.find(b"\x49\x44\x41\x54")
            if acTL < iDAT:
                return True
        return False