我正在尝试将 imgkit 图像转换为 PIL 图像以对其进行修改。当我尝试使用文件时,imgkit 成功地将 html 转换为图像。当我使用 BytesIO 并尝试转换为 PIL 图像时,我收到错误消息。
这是我的代码:
img = imgkit.from_string(template.render(a=elements, r=range(len(elements))), False, config=config)
bytesImg = BytesIO(img)
bytesImg.seek(0)
image = Image.open(bytesImg) #error here
PIL.UnidentifiedImageError:无法识别图像文件 <_io.BytesIO object at 0x102082680>
我已经看到了这个和这个。我是错误地将 imgkit 图像转换为字节还是有其他错误?
使用 Pillow 8.1 Python 3.9 和 imgkit 1.0.2