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.