【发布时间】:2020-11-22 08:47:17
【问题描述】:
from PIL import Image, ImageDraw, ImageFont
@client.command()
async def test(ctx):
image = Image.open('background.png')
font = ImageFont.truetype('arial.ttf', size=35)
draw.text((0, 0), f"Example", fill="white", font=font)
draw.save("image.png")
await ctx.send(File=discord.File("image.png"))
我将如何发送使用Pillow.py 创建的图像而无需先保存图像。我试图通过 Stack Overflow 搜索以找到对此的有效响应,但是我没有找到任何有效的方法。任何帮助表示赞赏!
以前我尝试使用 IO 来解决这个问题,但它最终只是发送空文件。
【问题讨论】:
-
你把图片转成base64,然后用fpio阅读器读取
-
@Saddy 你是这个意思吗?
my_string = base64.b64encode(image.tobytes()) file = discord.File(fp=my_string, filename="skills.png") await ctx.send(file=file) -
是这样的。我的版本略有不同,但如果它有效,它会工作
-
@Saddy 这个不行,呵呵。你能发布你的版本,我可以测试一下吗? (有点想知道我是否走在正确的轨道上)
标签: python python-imaging-library discord.py