from PIL import Image, ImageDraw, ImageFont
# get an image
base = Image.open("Pillow/Tests/images/hopper.png").convert("RGBA")
# make a blank image for the text, initialized to transparent text color
txt = Image.new("RGBA", base.size, (255,255,255,0))
# get a font
fnt = ImageFont.truetype("Pillow/Tests/fonts/FreeMono.ttf", 40)
# get a drawing context
d = ImageDraw.Draw(txt)
# draw text, half opacity
d.text((10,10), "Hello", font=fnt, fill=(255,255,255,128))
# draw text, full opacity
d.text((10,60), "World", font=fnt, fill=(255,255,255,255))
out = Image.alpha_composite(base, txt)
out.show()
查看ImageMagick的绘图-将形状或文本添加到图像https://imagemagick.org/Usage/draw/#text
也许您可以使用Wand,这是一种基于ctypes的Python简单ImageMagick绑定,下面是关于draw text https://docs.wand-py.org/en/0.6.2/guide/draw.html#texts的文档
基本上,您只需要一个用于编辑图像的库。对于Python,您可以使用最著名的pillow
然后,您只需通过discord.py检索用户名和其他要在图像上显示的信息,然后您就可以使用pillow的方法将文本放在背景图像上或您希望储存在机器人文件中的任何内容
以下是来自pillow's doc的示例:
您可以保存用
out.save('your-file-path.png')
编辑的图像,并用channel.send(file=discord.File('your-file-path.png'))
发送,而不是out.show()
相关问题 更多 >
编程相关推荐