Skip to content

Instantly share code, notes, and snippets.

@zipus
Created June 18, 2012 13:55
Show Gist options
  • Save zipus/2948483 to your computer and use it in GitHub Desktop.
Save zipus/2948483 to your computer and use it in GitHub Desktop.
Canvas to Image | Image to Canvas
//extracted of http://davidwalsh.name/convert-canvas-image
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;
}
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