用Ruby或Python解析SVG的库

时间:2021-09-06 15:47:26

SVG is a huge standard, which is based on XML. I have parsed SVG as XML in the past. However, some things are hard.

SVG是一个巨大的标准,它基于XML。我过去曾将SVG解析为XML。但是,有些事情很难。

For example, I would like to know the size of a group. As far as I can tell, this is only possible by recursively stepping through all the children in the group (noting all their transformations) and accumulating their sizes.

例如,我想知道一个组的大小。据我所知,这只能通过递归地逐步遍历组中的所有子项(记录它们的所有变换)并累积它们的大小来实现。

I would love to have a library that could do stuff like that for me. Does something like this exist?

我很想拥有一个可以为我做这样的事情的图书馆。这样的事情存在吗?

1 个解决方案

#1


6  

In python you have pysvg:

在python中你有pysvg:

import pysvg.parser

svg = pysvg.parser.parse(<filename>)
print svg.get_width(), svg.get_height()

#1


6  

In python you have pysvg:

在python中你有pysvg:

import pysvg.parser

svg = pysvg.parser.parse(<filename>)
print svg.get_width(), svg.get_height()