Giter Club home page Giter Club logo

Comments (11)

davidmz avatar davidmz commented on August 24, 2024

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.

adamcoulombe avatar adamcoulombe commented on August 24, 2024

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.

charlesr1971 avatar charlesr1971 commented on August 24, 2024

@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.

davidmz avatar davidmz commented on August 24, 2024

@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.

charlesr1971 avatar charlesr1971 commented on August 24, 2024

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.

charlesr1971 avatar charlesr1971 commented on August 24, 2024

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.

davidmz avatar davidmz commented on August 24, 2024

No, it wouldn't work. The only way to obtain APNG data is fetch/XHR.

from apng-js.

charlesr1971 avatar charlesr1971 commented on August 24, 2024

@davidmz David. Thanks for your advice.

What part of the method outlined in:

https://jsfiddle.net/donmccurdy/jugzk15b/

Would fail?

Thanks

from apng-js.

davidmz avatar davidmz commented on August 24, 2024

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.

charlesr1971 avatar charlesr1971 commented on August 24, 2024

@davidmz Thanks for your help...

from apng-js.

charlesr1971 avatar charlesr1971 commented on August 24, 2024

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)

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.