我读过几个线程,也试过几个线程,但是我无法解决这个问题。
我有一个简单的SVG文件:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 289 144.94">
<defs>
<style type="text/css">
@import url('https://fonts.googleapis.com/css2?family=Cabin:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700');
</style>
<style type="text/css">
@import url('https://fonts.googleapis.com/css2?family=Cabin:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700');
</style>
<style type="text/css">.cls-11{font-size:53.58px;}
</style>
</defs>
<text class="cls-11" textLength="110" lengthAdjust="spacingAndGlyphs" transform="translate(160.98 45.54)">M2/1</text>
</svg>但是我无法在Python中为这个SVG生成一个PNG输出。我试过cairosvg,pyvips,wandpy,但是都有一些问题。主要有两个问题:
导入的字体未加载/未加载recognized.
我也可以用它生成另一种基于像素的格式,或者使用另一种编程语言/库。
发布于 2022-04-06 08:05:56
from cairosvg import svg2png
from cairosvg import svg2png
svg_code = """
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"/>
<line x1="12" y1="8" x2="12" y2="12"/>
<line x1="12" y1="16" x2="12" y2="16"/>
</svg>
"""
svg2png(bytestring=svg_code,write_to='output.png')这个例子是由一个名为"JWL“的用户提供的,下面的链接是否回答了您的问题?
https://stackoverflow.com/questions/71763093
复制相似问题