【发布时间】:2020-11-29 18:23:33
【问题描述】:
我目前正在开发一个将两个图像与 PIL 粘贴在一起的程序,但是 PIL 很奇怪,所以我必须做一些额外的事情才能使用链接。无论如何,现在我不能使用 PIL 输出的内容,因为: AttributeError:“图像”对象没有属性“getvalue”
这是我的代码的重要部分:
async with aiohttp.ClientSession() as session:
async with session.get(avurl) as second_image:
image_bytes = await second_image.read()
with Image.open(BytesIO(image_bytes)).convert("RGB") as first_image:
output_buffer = BytesIO()
first_image.save(output_buffer, "png")
output_buffer.seek(0)
async with aiohttp.ClientSession() as session:
async with session.get("https://i.imgur.com/dNS0WJO.png") as second_image:
image_bytes = await second_image.read()
with Image.open(BytesIO(image_bytes)) as second_image:
output_buffer = BytesIO()
second_image.save(output_buffer, "png")
output_buffer.seek(0)
first_image.paste(second_image, (0, 0))
buf = io.BytesIO()
first_image.save(buf, "png")
first_image = first_image.getvalue()
谁能告诉我我缺少哪行代码来解决这个问题?或者我做错了什么?
【问题讨论】:
标签: python image image-processing python-imaging-library