-
Notifications
You must be signed in to change notification settings - Fork 49
How do you include this on a web page? #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You should do this (I'll use async/await syntax for brevity): const apng = parseAPNG(buffer); // buffer is an ArrayBuffer with the image data
await apng.createImages(); // making images for all frames
const player = await apng.getPlayer(ctx); // ctx is a canvas 2D context
player.play() // play apng on canvas
...
player.pause() // pause playback |
Thanks for your help. I submitted PR #3 to maybe help others get started, the whole babel/webpack workflow was not something I was very familiar with when I found your library, although I am glad to know it now! |
@davidmz Is it possible to read data from IMG tag rather than accessing the data through a file INPUT tag, using filereader(). I have several APNG that load on a webpage, I want loop over these images and access data like duration etc |
@charlesr1971 yes, it possible but not from IMG itself. You should load the image binary data from the src URL (via fetch API or XHR) and parse it using this library. Also, you can use a bit more hi-level library, https://github.com/davidmz/apng-canvas that have the APNG.animateImage method for it. Note that there are some limitations. |
David. Thanks for your help. I will have a look at the other library apng-canvas, but I wanted to try and avoid XHR How about this method? After an image has loaded, I recreate it as a Canvas, using:
And then use:
Like: https://jsfiddle.net/donmccurdy/jugzk15b/ Then I can use:
To access the array buffer and pass it into:
|
Of course, with my previous method, I wouldn’t need to build the image out. I would just add the APNG duration data, underneath the source image, once it is available. |
No, it wouldn't work. The only way to obtain APNG data is fetch/XHR. |
@davidmz David. Thanks for your advice. What part of the method outlined in: https://jsfiddle.net/donmccurdy/jugzk15b/ Would fail? Thanks |
Sorry, but I cannot provide detailed consultation via Github issues. The getImageData isn't returning raw PNG data, it event isn't have PNG format at all (https://developer.mozilla.org/ru/docs/Web/API/ImageData). It is just an uncompressed 'screenshot' without any animation info. |
@davidmz Thanks for your help... |
And finally, I managed to resolve this problem by using apng-canvas:
Simple when you know how... Anyway, great libraries! Thanks... |
I want the ability to play/pause the APNG on a webpage. I am having trouble understanding from the instructions on the readme exactly how you get an APNG on the webpage and use this library to control it.
I saw the demo and see that it does this, but the index.js doesnt look like your documentation.
The text was updated successfully, but these errors were encountered: