Convert Raphael SVG to image (png etc) client side [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:26:01

问题:

Possible Duplicate:
Convert SVG to image (JPEG, PNG, etc.) in the browser

I have a small project where users construct a diagram using Raphael and then export the composed diagram to an image to save.

Problem is it has to run offline. http://www.nihilogic.dk/labs/canvas2image/ will not work as it requires a canvas, not the Raphael generated SVG.

Is there a way (javascript) that I can export an image from the SVG?

回答1:

Yes, that duplicate question was a big help. canvg combined with canvas2image sorted me out.

So I created the SVG using Raphael. Then on a button click, saved the inner HTML of the div holding the SVG in a variable, then used that in canvg, hiding the SVG div. I could then use the ID of the canvas for canvas2image. It only really worked well for PNG.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!