简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM