Skip to content

Instantly share code, notes, and snippets.

@cuibonobo
Created February 3, 2014 14:57
Show Gist options
  • Select an option

  • Save cuibonobo/8785297 to your computer and use it in GitHub Desktop.

Select an option

Save cuibonobo/8785297 to your computer and use it in GitHub Desktop.
Convert HTML5 `canvas` elements to an image. Taken from http://davidwalsh.name/convert-canvas-image
// Converts image to canvas; returns new canvas element
function convertImageToCanvas(image) {
var canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
canvas.getContext("2d").drawImage(image, 0, 0);
return canvas;
}
// Converts canvas to an image
function convertCanvasToImage(canvas) {
var image = new Image();
image.src = canvas.toDataURL("image/png");
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment