first of all, I know that accessing toDataURL
method of canvas when its source image is from another origin is a security issue.
but in my case, I am u
There exists a library that abstracts the svg --> canvas --> png and adds a method to the SVG element so that in any browser you can just call mySvg.toDataUrl() with a callback and the option "canvg":
https://github.com/sampumon/SVG.toDataURL
This implementation takes into account security exceptions so you can get past the permissions error you are encountering.
<script type="text/javascript" src="http://canvg.github.io/canvg/rgbcolor.js"></script>
<script type="text/javascript" src="http://canvg.github.io/canvg/StackBlur.js"></script>
<script type="text/javascript" src="http://canvg.github.io/canvg/canvg.js"></script>
<script>
<script type="text/javascript" src="http://rawgit.com/sampumon/SVG.toDataURL/master/svg_todataurl.js"></script>
mySVGelement.toDataURL("image/png", {
renderer: "canvg"
callback: function(data) {
image.src = data;
}
});
</script>
Compatibility:
Browser E x p o r t i n g f o r m a t
SVG+XML PNG/canvg PNG/native
IE 9+ 9+ -
Chrome + + 33+ ²
Safari + + -
Firefox + + 11+ ¹
Opera + + -
In my case, I changed the graphic elements that make up the image from svg to png. When using svg, I am seeing a security error in IE 11 (and 10), not Chrome, when I use toDataURL. Building the graphic using png elements, it's fine.
There is a 2nd problem with svgs not resizing properly in IE 11, so that's another strike against using svgs with IE.