eight04 / pyAPNG

A Python module to deal with APNG files.
MIT License
42 stars 11 forks source link
apng python python2 python3

pyAPNG

.. image:: https://travis-ci.org/eight04/pyAPNG.svg?branch=master :target: https://travis-ci.org/eight04/pyAPNG

.. image:: https://readthedocs.org/projects/pyapng/badge/?version=latest :target: http://pyapng.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status

A Python module to deal with APNG file.

Features

Dependencies

Development dependencies

Installation

From pypi <https://pypi.org/project/apng/>__::

pip install apng

Usage

Convert a series of images into APNG animation:

.. code:: python

from apng import APNG

APNG.from_files(["1.jpg", "2.jpg", "3.jpg"], delay=100).save("result.png")

Use different delays:

.. code:: python

from apng import APNG

files = [ ("1.jpg", 100), ("2.jpg", 200), ("3.jpg", 300) ]

im = APNG() for file, delay in files: im.append_file(file, delay=delay) im.save("result.png")

Extract frames from an APNG file:

.. code:: python

from apng import APNG

im = APNG.open("animation.png") for i, (png, control) in enumerate(im.frames): png.save("{i}.png".format(i=i))

Add a text chunk to the PNG file:

.. code:: python

from apng import PNG, make_text_chunk

im = PNG.open("image.png") im.chunks.append(make_text_chunk(key="Comment", value="Some text")) im.save("image.png")

Performance

If you want to convert some large JPGs into animation, the library has to convert your JPGs into PNGs then merge them into a single animation APNG file. The problems are:

  1. It is extremely slow.
  2. The file size of the APNG is extremely large. Probably 5x of the original or more.

In this case, I suggest trying an animation format called "ugoira", which is implemented by Pixiv.net. There is also an image viewer named "HoneyView" which can view it locally.

Document

http://pyapng.readthedocs.io/en/latest/

Todos

Changelog