我正在使用svgwrite和生成 svg 文件,如何将它们转换为 PNG 或 JPEG?
我需要导入一个现有的svg图片,并在其上添加圆形和方形等元素.我的文件是'test.svg',所以我尝试了dwg = svgwrite.Drawing('test.svg')
但它创建了一个没有任何东西的新svg文件.我使用python lib svgwrite,你对我有什么想法吗?
谢谢你,对不起我的英语......我尽我所能!
我正在尝试将SVG文件连接到Web scraper.
如何使用svgwrite更改字体和文本大小?我知道我必须定义一个CSS样式,并以某种方式将其连接到文本对象.但是这是怎么做的?
这是我到目前为止的代码
import svgwrite
svg_document = svgwrite.Drawing(filename = "test-svgwrite3.svg",
size = ("1200px", "800px"))
#This is the line I'm stuck at
#svg_document.add(svg_document.style('style="font-family: Arial; font-size : 34;'))
svg_document.add(svg_document.rect(insert = (900, 800),
size = ("200px", "100px"),
stroke_width = "1",
stroke = "black",
fill = "rgb(255,255,0)"))
svg_document.add(svg_document.text("Reported Crimes in Sweden",
insert = (410, 50),
fill = "rgb(255,255,0)",
#This is the connection to the first line that I'm stuck at
#style = 'style="font-family: Arial; font-size : 104;'))
print(svg_document.tostring())
svg_document.save()
Run Code Online (Sandbox Code Playgroud) 我在我的Python代码中使用svgwrite模块,我想设置一个背景颜色.到目前为止,我还没有找到任何东西.有办法吗?
我希望在初始化过程中有所作为:
import svgwrite
canvas = svgwrite.drawing.Drawing(fill="#225566") # or background="#225566", or sth similar
canvas.save('image.png')
Run Code Online (Sandbox Code Playgroud)
或者我可以在整个地方绘制矩形,但这很奇怪.
我在 python 中使用 svgwrite 根据我的 Tensorflow 模型生成输出以输出模拟手写文本。我当前的设置需要一个字符串数组来表示换行符,但是生成的文本大小不一致,有时会在行中的最后一个单词之后呈现尴尬的间距,例如

是否可以将文本换行添加到单个长行中,当当前行达到给定的最大宽度时会自动添加换行符?Google 搜索将我带到 svgwrite 页面并建议使用TextArea,但给出的示例是 HTML。
def _draw(self, strokes, lines, filename, stroke_colors=None, \
stroke_widths=None, background_color='white'):
lines = [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit,",
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris",
"nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in",
"reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."
]
stroke_colors …Run Code Online (Sandbox Code Playgroud) 我正在尝试更正以下代码:
import svgwrite
dwg = svgwrite.Drawing('test.svg', profile='tiny')
dwg.add(dwg.circle((10, 0), 20 , fill='rgb(0,0,255)', id='rrr', class='#t'))
dwg.save()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
dwg.add(dwg.circle((10, 0), 20 , fill='rgb(0,0,255)', id='rrr', class='#t'))
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
这是为什么?显然 svgwrite 无法向元素添加类属性
我正在尝试生成由一些硬编码字符串组成的 word_cloud 的 svg(到目前为止,稍后这些字符串将动态生成)。下面是生成word_cloud的Python代码:
from os import path
from wordcloud import WordCloud
d = path.dirname(__file__)
# Read the whole text.
#text = open(path.join(d, 'test.txt')).read()
mytext = ['hello, hi, ibm, pune, hola']
# Generate a word cloud image
wordcloud = WordCloud().generate(text)
import svgwrite
# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
Run Code Online (Sandbox Code Playgroud)
现在,我不想使用 plt.show(),而是想将 wordcloud 变量传递给 svgwrite 方法,如下所示:
svg_document = svgwrite.Drawing(filename = "test-svgwrite.svg",profile = 'full')
svg_document.add(svg_document.text(wordcloud,
insert = (210, 110)))
svg_document.tostring()
svg_document.save()
Run Code Online (Sandbox Code Playgroud)
然而,这个创建的 SVG …