Freshchris
Freshchris

Reputation: 1251

Download Canvas as Image without .toDataUrl()

Is it possible to download the (edited) Image of a Canvas Element in HTML without using the .toDataUrl() function? I tested some frameworks but they still use this function.

Upvotes: 4

Views: 589

Answers (1)

dandavis
dandavis

Reputation: 16726

In newer browsers, you can get MUCH larger images and faster performance with the async method canvas.toBlob(callback, mimeType, qualityArgument);

see the mdc article for details and compat (basically IE10+)

the blob doesn't have the same size limits that dataURL realistically face in many browsers and devices, so where supported, it leads to a much better user experience.

if you later want to turn the blob into a dataURL, use FileReader.readAsDataURL(blob)

Upvotes: 4

Related Questions