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;