【发布时间】:2018-07-03 13:58:38
【问题描述】:
我正在编写一个程序来将文本放置到特定图像上。我打算让该程序供多个用户使用,因此每次所需的图像都会有一个不同的目录。
如何操作图像的路径以使这成为可能?我确实打算将“空白”图像以及脚本附加到用户,但我想知道是否可以将图像嵌入脚本中,所以我只发送一个文件。
这是我的第一个 Python 程序,如果解决方案非常明显,我们深表歉意。
im=Image.open(r"C:\Users\Desktop\image") #Opens image
font_type = ImageFont.truetype(r"C:\Windows\Fonts\Arial.ttf", 59)
txt=Image.new('L', (4677,3307))
d = ImageDraw.Draw(txt)
d.text( (3700, 3060), OD, font=font_type, fill= 255)
w=txt.rotate(90, expand=1) #Rotates the OD annotation 90 degrees
im.paste( ImageOps.colorize(w, (34,0,0), (255,100,84)), (242,60), w)
路径每次都会不同,因此它必须能够识别图像保存在用户计算机上的任何位置。
【问题讨论】:
-
请澄清问题,在您的问题中包含minimal, complete and verfiable。如有必要,您也应该能够将图像附加到问题中。
标签: image python-3.x path filepath