【发布时间】:2021-08-23 13:51:33
【问题描述】:
如何将 SVG 转换为在 Python 中使用内联样式?例如,我想转换这个:
<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 576 576">
<defs>
<style>.cls-1{fill:#d1b037;stroke:#1e1e1e;stroke-width:0.25px;}</style>
</defs>
<rect class="cls-1" width="576" height="576"/>
</svg>
到
<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 576 576">
<rect class="cls-1" width="576" height="576" fill='#d1b037' stroke='#1e1e1e' stroke-width='0.25px'/>
</svg>
这是一个简单的例子。我需要支持不同的元素,例如 path 以及共享同一组属性的多个类。
Python 中有 SVG/XML 解析器,但没有用于解析样式标签。如果用另一种语言/工具更容易做到,我会接受的。
【问题讨论】: