Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving an Animation Created with HTML5 Canvas

Tags:

html5-canvas

Is it possible to give an end user the ability to save as a single file an animation created client side with HTML5 Canvas - other than saving the entire HTML of the page?

There are plenty of tutorials on how to save as PNG, but the animation is lost in these cases.

like image 633
GeorgeU Avatar asked Nov 21 '11 19:11

GeorgeU


People also ask

How do I export an animation from HTML5?

Select File > New to display the New Document dialog. Select the Advanced tab from the top of the screen and click the HTML5 Canvas option. This opens a new FLA with Publish Settings modified to produce HTML5 output.

How do I save an animation in HTML?

Internet Explorer (IE): In the animation window, open IE's View menu (at the top of the window) and select Source. A Notepad window will open displaying HTML code. In the Notepad window, open the File menu and select Save As. Give the file a suitable name ending in ".

Can HTML5 be used for animation?

You can create animations with HTML5 by combining HTML, CSS, and JavaScript (JS), with which you can build shapes. Also, you can control animations and edit images, video, and audio by means of JS or CSS elements, all of which you then add to a drawing board, which you set up with the <canvas> element.


1 Answers

There is not an "easy" way to do this.

Here is a similar question... Grabbing each frame of an HTML5 canvas

You could follow this approach and grab the frames and submit these to a server-side script to compile them into an animated GIF.

Another option, though non-trival, would be to implement a pure JavaScript GIF encoder. The GIF specification can be found here, http://graphcomp.com/info/specs/gif89a.txt

If the color table stays the same in each frame, you could probably splice together the frames from already encoded GIF urls without having to compress the pixel level data. You would still need to decode the base64 stream from Canvas.toDataURL.

like image 123
Charles Avatar answered Oct 21 '22 00:10

Charles