Skip to content

Instantly share code, notes, and snippets.

@av01d
Created July 23, 2020 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save av01d/24f4554274d100e8e9a5ea8ae10e1b78 to your computer and use it in GitHub Desktop.
Save av01d/24f4554274d100e8e9a5ea8ae10e1b78 to your computer and use it in GitHub Desktop.
Javsacript: Convert canvas to image, image to canvas
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