Skip to content
プロジェクト

davidmz/apng-canvas has 677 GitHub stars and 92 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-20 12:58 UTC. Last push 2022-12-04.

この数値の測り方

計測したスター増加

24時間
0
7日間
履歴を収集中
15日間
履歴を収集中
1か月
履歴を収集中

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

概要

APNG implementation on canvas.

開発ツール

apng-canvas v2.1.0

(README по-русски)

Library to display Animated PNG (Wikipedia, specification) in a browser using canvas.

Working demo: https://davidmz.github.io/apng-canvas/ (around 3 Mb of apng files)

Please note! API version 2 of the library is incompatible with the API version 1!

The library requires support from the following technologies in order to run:

These technologies are supported in all modern browsers and IE starting with version 10.

Some browsers (at the moment these are Firefox and Safari 8+) have native support for APNG. This library is not required for these browsers.

Usage example

APNG.ifNeeded().then(function() {
    var images = document.querySelectorAll(".apng-image");
    for (var i = 0; i < images.length; i++) APNG.animateImage(images[i]);
});

Limitations

Images are loaded using XMLHttpRequest, therefore, the HTML page and APNG image must be located on the same domain or the correct CORS header should be provided (for example, Access-Control-Allow-Origin: *). For the same reason, the library will not work on a local machine (using the protocol file://).

Important note! Compression proxies (turbo mode in Opera, "reduce data usage" mode in mobile Chrome, etc.), doesn't know about APNG format. These proxies transforms APNGs into static images. To prevent it for your images, they need to be served with Cache-Control: no-transform HTTP header (see big article about such proxies), or via HTTPS.

API

The library creates a global object APNG, which has several methods.

High-level methods:

Low-level methods:

Most methods work asynchronously and return the ES6 Promise object. Most browsers have built-in support for it. For others browsers, library uses polifill (included in the library). If you have not worked before with Promises, then you should read the review paper about this technology. The method description includes values of the Promise result in cases where it is fulfilled or rejected.

Build instructions

npm install
gulp build