Skip to content

Instantly share code, notes, and snippets.

@jberryman
Created April 30, 2012 19:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jberryman/2561736 to your computer and use it in GitHub Desktop.
Save jberryman/2561736 to your computer and use it in GitHub Desktop.
A jQuery one-liner for converting all html5 canvas elements in the DOM to PNGs
$('canvas').each(function(i,e){ var img = e.toDataURL("image/png"); $(e).replaceWith( $('<img src="'+img+'"/>').attr({width: $(e).attr("width"), height: $(e).attr("height"), style: $(e).attr("style") }) ) });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment