I'm doing to following:
- Generate an SVG document as a string
- Capture it in a
blob:
URL withnew Blob
andcreateObjectURL
- Create a
fabric.Image
object from it usingfromURL
- In the
fromURL
callback, callcanvas.add
to add the newImage
to the canvas
This is my code:
var svg = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height = "200"><foreignObject width="100%" height="100%"><text xmlns = "http://www.w3.org/1999/xhtml" style = "font-size: 40px; color: #FFFFFF">Example</text></foreignObject></svg>';
var svgBlob = new Blob([svg], {type: 'image/svg+xml'});
var svgURL = window.URL.createObjectURL(svgBlob);
fabric.Image.fromURL(svgURL,function(oIMG) {
oIMG.crossOrigin = 'Anonymous';
canvas.add(oIMG);
});
Then I try getImageData:
var dataImage = context.getImageData(0,0,canvas.width,canvas.height).data;
In Chrome, this gives me the error:
Uncaught DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
This is strange because I don't ever use any cross-origin URLs, only blob:
URLs.
In Firefox it works perfectly. The problem appears to be specific to Chrome.