To get binary (base64) data from HTML5 Canvas with JavaScript, we use the toDataURL
method.
For instance, we write
const jpegUrl = canvas.toDataURL("image/jpeg");
to call toDataURL
with "image/jpeg"
to return a base64 URL string with the canvas in JPEG format.
If we don’t pass in any argument, then a base64 string in PNG format is returned.