jnordberg / gif.js

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

Can't draw the generated gif onto canvas as expect #43

Closed Julyyq closed 9 years ago

Julyyq commented 9 years ago

Only first frame is shown, does canvas not support drawing gif ? Or, there's a bug within the generated gif ? Thanks very much.

jnordberg commented 9 years ago

Not supported by canvas

1j01 commented 9 years ago

For a while, chrome would draw GIFs animated on the canvas, but the spec says to only draw the first frame. If you need to draw animated GIFs on the canvas, you can use a library that will parse GIFs. If you just want to playback the frames such as to preview the GIF, you can handle that yourself by keeping ImageData objects or canvases.

Julyyq commented 9 years ago

@1j01 Thanks for your reply.I saw a library called fabricjs that draw animated images on canvas, but with using sprites, it's unconvince. I think it's painful to draw aniamated image onto canvas now.

1j01 commented 9 years ago

@Julyyq Have you tried libgif.js? Looks like you should be able to set auto_play and it should animate a GIF onto a canvas you give it.

Julyyq commented 9 years ago

@1j01 libgif tries to draw gif into canvas which is inside in a iframe, that is, I can't specific the canvas that I wanna draw in. And, Its propose is to make gif rubbable and plays like a video. Anyway, the library tells me that gif could be draw into canvas with some work-around.

1j01 commented 9 years ago

@Julyyq Yeah, that library doesn't really live up to its name. Maybe readwrite-gif instead? Both libraries it uses have both encoders and decoders, but neither jsgif nor omggif have documentation, so I guess readwrite-gif is an attempt at giving some kind of API to them, although I'm not sure why it uses both...