Snippets

Convert an Image to Canvas

The 0, 0 arguments map to coordinates on the canvas where the image data should be placed.

// 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;
}

Source: http://davidwalsh.name/detect-node-insertion...

Share this snippet

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Please respect the following rules: No advertising, no spam, no keyword in name field. Thank you!