如何使用Python PIL 1.1.7保存渐进式jpeg? [英] How to save progressive jpeg using Python PIL 1.1.7?
本文介绍了如何使用Python PIL 1.1.7保存渐进式jpeg?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过以下调用进行保存,这会引发错误,但是如果我删除了渐进式和优化选项,则会保存.
I'm trying to save with the following call and it raises error, but if i remove progressive and optimize options, it saves.
这是我无法运行的test.py:
Here is my test.py that doesn't work:
import Image
img = Image.open("in.jpg")
img.save("out.jpg", "JPEG", quality=80, optimize=True, progressive=True)
它会引发此错误:
Suspension not allowed here
Traceback (most recent call last):
File "test.py", line 3, in <module>
img.save("out.jpg", "JPEG", quality=80, optimize=True, progressive=True)
File "/Library/Python/2.6/site-packages/PIL/Image.py", line 1439, in save
save_handler(self, fp, filename)
File "/Library/Python/2.6/site-packages/PIL/JpegImagePlugin.py", line 471, in _save
ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])
File "/Library/Python/2.6/site-packages/PIL/ImageFile.py", line 501, in _save
raise IOError("encoder error %d when writing image file" % s)
IOError: encoder error -2 when writing image file
链接到图像: http://static.cafe.nov.ru/in.jpg (4.3 mb)
Link to image: http://static.cafe.nov.ru/in.jpg (4.3 mb)
推荐答案
这可能会起作用,但是您可能需要使缓冲区更大:
Here's a hack that might work, but you may need to make the buffer even larger:
from PIL import Image, ImageFile
ImageFile.MAXBLOCK = 2**20
img = Image.open("in.jpg")
img.save("out.jpg", "JPEG", quality=80, optimize=True, progressive=True)
这篇关于如何使用Python PIL 1.1.7保存渐进式jpeg?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文