将 svg 转换为 json

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17030724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 19:51:19  来源:igfitidea点击:

Converting svg to json

jsonsvgpathraphael

提问by dracula

I want to be able to create a svg image in Illustrator and convert it to json to be able to use it with Raphael js, as below.

我希望能够在 Illustrator 中创建一个 svg 图像并将其转换为 json 以便能够与 Raphael js 一起使用,如下所示。

How could this be done without a server side script?

如果没有服务器端脚本,如何做到这一点?

What I want:

我想要的是:

[0,0,255.3,298.5,{type:'path',path:'M 35.3 257.2 C 34.4 245.7 45.4 234.1 48.5 223 C 53.6 204.3 55 185 60 166.2 C 69.5 131 69.6 97.1 89.1 65.1 C 103.4 41.7 129.5 5.3 161.3 19.7 C 184.6 30.3 181.3 59.2 188.9 78.9 C 207.5 127.3 228.6 184.8 230.3 237.3 C 231.3 268.6 202.8 261.3 178.2 264 C 149.2 267.1 120 269.6 91 272.2 C 84.2 272.8 75.8 274.2 69 273 C 60.9 271.6 28.9 259.9 31.3 249.2','fill':'#39b54a','stroke':'none','stroke-width':'0','fill-opacity':'1','stroke-opacity':'0'}];

采纳答案by Brian

As I understood, your problem is that Raphael is not working with imported SVG. There is a way to make the SVG into a Raphael object and then you can use it with Raphael library. Chack out this website: http://irunmywebsite.com/raphael/SVGTOHTML_LIVE.php

据我了解,您的问题是 Raphael 无法使用导入的 SVG。有一种方法可以将 SVG 变成 Raphael 对象,然后您可以将它与 Raphael 库一起使用。查出这个网站:http: //irunmywebsite.com/raphael/SVGTOHTML_LIVE.php

回答by PeterVermont

Since svg is xml you can use an xml to json converter such as this: http://www.utilities-online.info/xmltojson

由于 svg 是 xml,您可以使用 xml 到 json 转换器,例如:http: //www.utilities-online.info/xmltojson

回答by gwintrob

Here's a solution using Python: https://github.com/gwintrob/svg-to-json

这是使用 Python 的解决方案:https: //github.com/gwintrob/svg-to-json

I stumbled across this GitHub repo that uses JS, but it didn't support a large SVG file: https://github.com/chrisfinch/svg-to-json

我偶然发现了这个使用 JS 的 GitHub 存储库,但它不支持大型 SVG 文件:https: //github.com/chrisfinch/svg-to-json