我是 Python 新手,我正在尝试访问 Google 的 QuickDraw 数据库并根据用户输入的列和行排列大量图像(矢量线),然后以 .svg 文件格式导出。到目前为止,我只设法将每个图像保存为 .gif 并显示它。如何以 3x3 网格和 .svg 格式排列它们?
这是我到目前为止的代码:
from PIL import Image, ImageDraw
from quickdraw.data import QuickDrawData
rows = int(input("How many rows do you want? "))
columns = int(input("How many columns do you want? "))
rows_columns = rows * columns
name_var = 0
for image in range(0,rows_columns):
qd = QuickDrawData()
duck = qd.get_drawing("duck")
duck_image = Image.new("RGB", (255,255), color = (255,255,255))
duck_drawing = ImageDraw.Draw(duck_image)
for stroke in duck.strokes:
for coordinate in range(len(stroke)-1):
x1 = stroke[coordinate][0]
y1 = stroke[coordinate][1]
x2 = stroke[coordinate+1][0]
y2 = stroke[coordinate+1][1]
duck_drawing.line((x1,y1,x2,y2), fill=(0,0,0), width=2)
duck_image.show()
name_var += 1
duck.image.save(f"my_duck{name_var}.gif")
理想情况下,结果应该是 .svg 文件格式。