Convert SVG to PNG and maintain CSS integrity

后端 未结 3 1047
眼角桃花
眼角桃花 2021-01-04 13:56

I am currently using canvg() and Canvas2Image to copy my SVG to a canvas and then convert the canvas to PNG. I would like to maintain the image format and not use PDF.

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 14:21

    just to make @Lars Kotthoff's answer more concrete. "example of how to export a png directly from an svg" has a working example. the code snippet/gist tries to first apply all css to the svg inline and then draw the image on the canvas and export the data as png. (internally it adopted svg-crowbar code). and i apply the technique in my project and it works smoothly - a download button that can download the svg image rendered using nvd3.

提交回复
热议问题