Convert canvas to an image with JavaScript

Assuming modifications to the image have been made, you can easily convert the canvas data to image data with the following snippet. The code above magically converts the canvas to a PNG data URI!

// Converts canvas to an image
function convertCanvasToImage(canvas) {
	var image = new Image();
	image.src = canvas.toDataURL("image/png");
	return image;
Enjoyed this article? Please consider donating: 3FVR5qaxYV8yAgNUUS7FC3o8c54YfDR5zK