Created
February 3, 2014 14:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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