jnordberg / gif.js

JavaScript GIF encoding library
http://jnordberg.github.io/gif.js/
MIT License
4.76k stars 668 forks source link

Can I control the render step by step? #54

Open faace opened 8 years ago

faace commented 8 years ago

for example, I use canvas to show an animation. when first frame is shown, i add this canvas to the GIF then i show the second frame, and i add the second canvas to the GIF and so on

am9x commented 7 years ago

check the sourcecode i found we can do this.

gif.on("progress",function(pst){
    //console.log("gifprogress",pst,this);
    myprogress.value=pst;
    //log("gifprogress"+Math.round(pst*100)+"%");
});

:)

1j01 commented 7 years ago

The answer to this is yes. You just have to call gif.addFrame each step, and then at some point stop adding frames and call gif.render. You can use a flag var recording = true; and only add frames if recording, and then when you want to finish the recording, recording = false; gif.render();