Giter Club home page Giter Club logo

pyapng's Introduction

pyAPNG

image

Documentation Status

A Python module to deal with APNG file.

Features

  • Merge multiple images into one APNG file. (It use Pillow to convert images into PNG format)
  • Read APNG file and extract each frames into PNG file.
  • It doesn't do any optimization but only concat the images. This might be changed in the future.

Dependencies

  • Pillow - Optional. You can still use pyAPNG without PIL but it can only read PNG files.

Development dependencies

  • pngcheck
  • See requirements.txt for other dev-dependencies.

Installation

From pypi:

pip install apng

Usage

Convert a series of images into APNG animation:

from apng import APNG

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

Use different delays:

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:

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:

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

  • Add optimizer?

Changelog

  • 0.3.4 (Mar 11, 2020)
    • Fix: exclude test files from the package.
  • 0.3.3 (Feb 11, 2019)
    • Fix: failed to extract frames containing multiple fdAT chunks.
  • 0.3.2 (Jul 20, 2018)
    • Add: make_text_chunk function.
    • Add: Chunk data class.
    • Change: now parse_chunks yields Chunk instead of a tuple. This should be safe since Chunk is a namedtuple.
  • 0.3.1 (May 13, 2018)
    • Add: universal wheel.
  • 0.3.0 (May 13, 2018)
    • Support Python 2.
    • Add: PNG method open_any, from_bytes.
    • Add: APNG method append_file, from_bytes.
    • Add: module function parse_chunks.
    • Drop: module function `is_png` and `chunks`.
    • Change: `PNG.open` now only reads PNG images. To read non-PNG images, use `PNG.open_any`.
    • Change: `APNG.append` now only accepts `PNG` instance. To append PNG files, use `APNG.append_file`.
  • 0.2.1 (Apr 19, 2018)
    • Add: support num_plays. (#4)
  • 0.2.0 (Dec 8, 2017)
    • Add test.
    • Add documents.
    • Add: support path-like object.
    • Fix: some chunks must appear before IDAT. (#1)
    • Fix: change chunks order in APNG. Some chunks are moved to the end of the file.
    • Fix: remove tRNS hack.
    • Fix: is_png shouldn't move file pointer. (#2)
  • 0.1.0 (May 30, 2016)
    • First release.

pyapng's People

Contributors

bburns avatar bpotard avatar chunan avatar eight04 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pyapng's Issues

Installed apng, but it seems to be empty

I've had the same results with Python 2.7 and 3.6.

import apng
method_list = [func for func in dir(apng) if callable(getattr(apng, func))]
print(method_list)
[]

Specifically,

from apng import APNG
"Cannot find reference 'APNG' in apng.py."

Maybe I am missing a dependency? I installed apng from the terminal for 3.6 and using the GUI in PyCharm for 2.7.

integer out of range for 'I' format code

Whenever I try to use this I get the error code integer out of range for 'I' format code

e.g.

APNG.from_files(images, delay=100).save('test.png')

Where images is a list of filepaths returns this error.

Python 2.7

APNG_DISPOSE_OP_PREVIOUS not handled

I got an APNG from here.

I tried extracting the frames using this, but found that there is a frame being extracted in only 1x1. Here's the extraction result

image

Then I used APNG Disassembler to extract the frames, I got that "missing frame".

image

It appears that frame 6 and 8 are the same, but frame 8 cannot be extracted using this. Here's the chunk structure acquired by pngcheck v2.3.0:

image

That fdAT at 0x226 with length only 17 is the missing one. I tried finding information by inspecting the documentation of both APNG and PNG, but cannot find any information about potentially reusing the frame. All other chunks seems also not indicating this reuse.

How to handle this case?

Note

PNG Frame Extract Weirdness

Been banging my head on writing an apng extraction myself. It somewhat works, but I run into issues with this file. Looks like your method runs into issues too..

The file was manually edited by the author to set the number of frames to 1. The technique of looking at the chunks themselves obviously gets by that. However, many of the images that get pulled out are corrupt.

My knowledge of PNG isn't the greatest, so I'm not sure if they're corrupt due to some process error in extracting or if they started that way... Either way, both of our extraction approaches cause some of the output files to be errored.

p1ng

not install the test

Hi

actualliy when run python setup.py install --root=<foo> --optimize, the test folder is also installed

please leave it out from installation

greetings

Pass repeat count by argument

Is it possible to pass a repeat count to the apng file? At the moment the repeat count stands at "-1" for repeat forever? Does the specification for apng even support repeat count?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.