How to use Fabric.js to save a canvas as an image
The following must be true:
- Your cross-domain
<img>
elements must contain acrossorigin
attribute. - The server hosting the images must return an Access-Control-Allow-Origin header in the response with either a wildcard, or your specific domain as the value.
- The browser must support CORS on
HTMLMediaElement
s, specificallyHTMLImageElement
s. This is only currently possible in Chrome, Firefox, and Opera 15+
This works well for me
function convertToImagen() {
canvas.deactivateAll().renderAll();
window.open(canvas.toDataURL('png'));
}
As a side note, remember that if you're developing on your local computer rather on a server, you will probably see this security error message.