Giter Site home page Giter Site logo

apng-canvas's Introduction

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

apng-canvas's People

Contributors

davidmz avatar dependabot[bot] avatar ha1f avatar kimdaewook avatar loo2k avatar q-- avatar ricordisamoa 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apng-canvas's Issues

Not working on local machine with file://

I'm having an issue running this on my local machine from files (getting CORS issues). You wrote that this is a known issue but I need it to work nonetheless. Any idea how to get this work on my local machine with Chrome WITHOUT running a server just to add the Access-Control-Allow-Origin header? Is there a reason why the files are fetched using XHR instead of simply getting them from a path?

Garbled character

when we use apng-canvas v2.1.0, it appears Garbled character in pages ( happens on Android System v6.0 )

Animation disappears

When the apng of an acyclic animation is used, there is no problem with the first loading, and then the animation with < img > appended disappears
`function addImg() {
var imgD = new Image();
imgD.src = ""
document.body.appendChild(imgD)

}

setInterval(function() {
addImg();
}, 3000)
`

Images only animate first time

Works great on desktop but on Android Chrome the images only animate once, if you refresh they are static images.
Any ideas?

Method to stop animation

I would like to be able to stop an animation. If simply removing the canvas from the DOM, the animation is still running in the background, calculating the frames. Is there a way to stop a specific image animation, or all animations completely?

How about making an encode lib?

Great works! I learned a lot from this lib. Right now, I am trying to make apng from a png list. However, I encountered some problems. I would like to know your implement, could you enlighten me?

Question: Is this approach able to apply with animated gif / animated SVG?

I'm original questioner of this stackoverflow article.
https://stackoverflow.com/questions/67660696/can-the-latest-openlayers-render-the-animated-marker-using-gif-apng-webp

The point is, old style web map engine uses div+img elements for the markers on the map, so animated XXX type image can be used for animated marker.
But the modern web map engine uses canvas or even webgl, so it became tough to realize animated marker.

I want to make it easy by creating some libraries for updating canvas context on each frame.
But I have less knowledge about such other formats like animated gif / SVG, so I'm not sure similar approach with your library can be used for such formats.
Do you give me advise if it is worse to customize this library for them or not, if you know?

If it is worse, I'll try to customize...

Способ получения Binary

  1. Бинарный код в Chrome, Firefox, Opera можно получить так:

var xhr = new XMLHttpRequest();
xhr.open('GET', img.src, true);
xhr.overrideMimeType('text/plain; charset=x-user-defined'); //binary XHR FTW? Probably XHR2 has binary xhr powers
xhr.onload = function(){
var binary = xhr.responseText.split('').map(function(e){return String.fromCharCode(e.charCodeAt(0) & 0xff)}).join('');

}
xhr.send(null);

  1. Я разработал http://html5tester.h19.ru/bin2/dev_tools_v2.js
    Инструменты для работы с бинарным кодом и PNG.
  2. Про IE сам думай!

cannot install using yarn

when I try to install with yarn:

yarn install apng-canvas I get an error:
error Received malformed response from registry for "apng-canvas". The registry may be down.

I can successfully install apng-js like this with yarn install apng-js

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.