Comments (11)
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
from apng-js.
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!
from apng-js.
@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
from apng-js.
@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.
from apng-js.
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:
ctx.drawImage()
And then use:
ctx.getImageData()
Like:
https://jsfiddle.net/donmccurdy/jugzk15b/
Then I can use:
new FileReader()
To access the array buffer and pass it into:
parseAPNG()
from apng-js.
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.
from apng-js.
No, it wouldn't work. The only way to obtain APNG data is fetch/XHR.
from apng-js.
@davidmz David. Thanks for your advice.
What part of the method outlined in:
https://jsfiddle.net/donmccurdy/jugzk15b/
Would fail?
Thanks
from apng-js.
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.
from apng-js.
@davidmz Thanks for your help...
from apng-js.
And finally, I managed to resolve this problem by using apng-canvas:
jQuery(document).ready(function(){
var animatedStickerImages = document.querySelectorAll('.animated-sticker-image');
var counter = 1;
[].forEach.call(animatedStickerImages, function(img) {
const duration = document.querySelector('##animated-sticker-image-duration-' + counter);
APNG.parseURL(img.src).then(function(data) {
if('playTime' in data){
var playTime = parseInt(data['playTime']/1000).toFixed(2) + "s";
duration.appendChild(document.createTextNode(playTime));
}
});
counter++;
});
Simple when you know how...
Anyway, great libraries! Thanks...
from apng-js.
Related Issues (20)
- Release apng-js 1.1.1 HOT 1
- Can the same be done for WebP? HOT 3
- Seek to a certain frame HOT 4
- Player scaling HOT 3
- Simple implementation HOT 3
- Build failing HOT 1
- Play/stop/pause aPNG HOT 1
- Stop/play parsed aPNG HOT 12
- Possible to place the animation somewhere else on canvas? HOT 2
- I want to play the specified frame how to achieve? HOT 3
- frame show bug HOT 1
- Transparency applied to non-changed pixels? HOT 4
- Use in node.js HOT 3
- PNG to APNG in NodeJS? HOT 1
- i try to use getPlayer but receive an err Image creation error(in react) HOT 1
- help:I have an APNG image, which will be truncated a lot when placed in your demo HOT 4
- Modify and export new APNG
- Updating and contributing HOT 1
- Apng is not supperted in some App。 Using apng-canvas solves this question。 But is Apng-js supported to the apng-canvas????? HOT 1
- Add type for this project. HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apng-js.