将 SVG 转换为 numpy 数组

Jon*_*ler 5 python svg numpy

我正在为 python 库编写一个函数,在其中一个函数中我需要将 SVG 字符串作为输入,即

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink"  >
    <rect style="stroke-width:1; fill:rgb(255, 255, 255); stroke:black; " x="0" y="0" height="100px" width="200px"  />
    <text x="210" y="110"  >
    Hello World
    </text>
</svg>
Run Code Online (Sandbox Code Playgroud)

我想要得到一个光栅化图像,如下所示:

svg 图像

但是,我需要在 python 中访问该图像,最好以 numpy 数组的形式。

我知道这可以使用外部可用的软件(即 inkscape 或 imagemagic)来完成,但我明确需要能够在纯 python 中执行此操作。此外,为了能够将其分发给不同平台上的广泛用户,我无法支持编译后端(与 cairo 一样)。

是否有任何 python 包可以以字符串格式获取 SVG 图像并以某种方式返回表示光栅化图像的 numpy 数组?