how to convert svg to png image in internet Explorer?

前端 未结 1 1062
天命终不由人
天命终不由人 2020-12-20 06:10

i have a chart that created with highchart. i need to save svg to png in internet Explorer. i use from follow code and exist security Error in ie11.

var canv         


        
相关标签:
1条回答
  • 2020-12-20 06:34

    I didn't found an satisfying dupe target, so I'll rewrite it as an answer :


    Drawing an SVG image through drawImage method will taint the canvas in IE < Edge for security reasons.

    This operation is somehow sensitive for browsers, since svg images imply to parse some XML, and that it can contain some tricky elements (though IE doesn't support <foreignObject>...)
    So quite often, browsers will add security restrictions when SVG images are drawn to it, and will block all exporting methods.

    This is the case in safari > 9 when an <foreignObject> is drawn on it, this was also the case in chrome, but only when the image comes from an Blob (an implementation bug, but they finally leveraged the security restriction altogether anyway).
    And then in IE < Edge, with any SVG.

    The only way to workaround this issue is to parse yourself the SVG, and then use the canvas' methods to reproduce it.

    This is all doable, but can take some time to implement, so even though I don't really like it, you'd probably be better using an library like canvg, which does exactly this (parsing + rendering with canvas methods).

    0 讨论(0)
提交回复
热议问题