How To Save Progressive Jpeg Using Python PIL 1.1.7?
I'm trying to save with the following call and it raises error, but if i remove progressive and optimize options, it saves. Here is my test.py that doesn't work: import Image img =
Solution 1:
import PIL
from exceptions import IOError
img = PIL.Image.open("c:\\users\\adam\\pictures\\in.jpg")
destination = "c:\\users\\adam\\pictures\\test.jpeg"
try:
img.save(destination, "JPEG", quality=80, optimize=True, progressive=True)
except IOError:
PIL.ImageFile.MAXBLOCK = img.size[0] * img.size[1]
img.save(destination, "JPEG", quality=80, optimize=True, progressive=True)
PIL encodes part of the image at a time. This is incompatible with the 'optimize' and 'progressive' options.
Edit: You need to import PIL.Image, PIL.ImageFile
for newer versions of PIL / Pillow.
Solution 2:
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)
Solution 3:
If you have installed PIL using pip, uninstall it and instal pillow. The pillow library has the edge version of PIL library with it. The PIL from pip is too old. If you update to pillow instead of PIL, you don't have to set PIL.ImageFile.MAXBLOCK. It is taken care of automatically.
If you used git submodule of just have PIL source code downloaded in to repo, make sure you download the latest source from GitHub and use it.
Post a Comment for "How To Save Progressive Jpeg Using Python PIL 1.1.7?"