Python 在不协调时发送枕头图像而不保存图像

Python 在不协调时发送枕头图像而不保存图像,python,python-imaging-library,discord.py,Python,Python Imaging Library,Discord.py,如何发送使用Pillow.py创建的图像而不必先保存图像。我曾尝试通过堆栈溢出搜索,以找到对此的有效响应,但没有找到任何有效方法。感谢您的帮助! 以前我试着用IO来解决这个问题,但结果只是发送空文件 from PIL import Image, ImageDraw, ImageFont @client.command() async def test(ctx): image = Image.open('background.png') font = ImageFont.truety

如何发送使用
Pillow.py创建的图像而不必先保存图像。我曾尝试通过堆栈溢出搜索,以找到对此的有效响应,但没有找到任何有效方法。感谢您的帮助!
以前我试着用IO来解决这个问题,但结果只是发送空文件

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"))

使用seek可以解决问题。

您将图像转换为base64,然后使用fpio readerSee@Saddy读取它,您的意思是这样吗
my_string=base64.b64encode(image.tobytes())file=discord.file(fp=my_string,filename=“skills.png”)等待ctx.send(file=file)
是这样的。我的版本稍有不同,但如果可以的话works@Saddy这个不行,呵呵。你可以发布你的版本,我可以测试一下吗?(有点想知道我是否在正确的轨道上)
with io.BytesIO() as image_binary:
                    image.save(image_binary, 'PNG')
                    image_binary.seek(0)
                    await ctx.send(file=discord.File(fp=image_binary, filename='image.png'))