Pillow saving to BytesIO or StringIO KeyError: "JPG"

Pillow saving to BytesIO or StringIO KeyError: "JPG"

我有一个 Pillow Image 对象图像,我尝试使用 image.save(temp, format="jpg")

将其保存到名为 temp 的 IO.BytesIO 对象中

当我 运行 然而,它给出了一个 KeyError: "JPG" 在这一行 save_handler = SAVE[format.upper()]

谢谢!

格式叫jpeg,不是jpg,所以直接用:

image.save(temp, format="jpeg")

有关可能值的参考(或 PIL.Image.SAVE.keys()),请参阅 Image file formats