python - 枕头保存到 BytesIO 或 StringIO KeyError : "JPG"

标签 python python-3.x python-imaging-library bytesio

我有一个 Pillow Image 对象图像,我尝试使用 image.save(temp, format="jpg") 将其保存到名为 temp 的 IO.BytesIO 对象

但是,当我运行此命令时,它会在这一行给出 KeyError: "JPG"save_handler = SAVE[format.upper()]

谢谢!

最佳答案

该格式称为jpeg,而不是jpg,因此只需使用:

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

参见Image file formats引用可能的值(或PIL.Image.SAVE.keys())

关于python - 枕头保存到 BytesIO 或 StringIO KeyError : "JPG",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37791782/

相关文章:

python - 试图从谷歌抓取图像

python - 在 pytesseract 中应用用户模式

python - 对数据框 pandas 的列中存在的列表执行计算

python - 带有 lambda 函数字典的 python 中的奇怪行为

python - 如何找到图像中的矩形

python - 如何在 Python 中创建一个空的 n*m PNG 文件?

python-2.7 - IO错误:Cannot open image while generating barcode after freezing using py2exe

python - 如何编辑交叉表的输出以显示精确到小数点后第二位的百分比?

Python networkx 和持久性(可能在 neo4j 中)

python - 如何将扩展 ascii 与 bs4 url​​ 一起使用