pythonpngapng

Reading animated PNGs in Python?


PyPNG, the most widely used PNG library for Python, doesn't seem to support animated PNGs. There's a library for writing animated PNGs, but I can't find an equivalent one for reading them. Anyone know a way of getting the frames out of this little supported image format?


Solution

  • There's a library for APNGs now - https://github.com/eight04/pyAPNG

    > pip install apng
    

    Extract frames from APNG file:

    from apng import APNG
    
    im = APNG.open("animation.png")
    i = 0
    for png, control in im.frames:
        png.save("{i}.png".format(i=i))
        i += 1
    

    It also supports creating APNGs.