How to save canvas as a png image with JavaScript?

Spread the love

To save canvas as a png image with JavaScript, we call the toDataURL method.

For instance, we write

const canvas = document.getElementById("alpha");
const dataURL = canvas.toDataURL("image/png");

to select the canvas with getElementById.

Then we call toDataURL on it with 'image/png' to convert the canvas content to a png base64 string.

Leave a Reply

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