1

I'm trying to use PIL to save some Progressive, Retina-sized images for use on the iPad 3, but keep receiving the "encoder error -2" mentioned in the question title.

I am aware that this is a known PIL + Jpeg issue, and after some reading I heard it could be solved by adding something like this to your code:

import PIL
from PIL import ImageFile
from exceptions import IOError

try:
    img.save("img.jpg", "JPEG" , quality=80, progressive=True)
except IOError:
    PIL.ImageFile.MAXBLOCK = img.size[0] * img.size[1]
    img.save("img.jpg", "JPEG" , quality=80, progressive=True)

However, even after using the above method to increase PIL's Maxblock, my script still throws an "encoder error -2". I also tried making the MAXBLOCK obscenely large, but had no luck with that, either:

PIL.ImageFile.MAXBLOCK = 2048 ** 10

The images I am trying to process are fairly large (2048 x 2048), but I'm hesitant to believe that they are simply too large for PIL to handle.

Has anyone else encountered/resolved this type of issue?

M Barrettara
  • 103
  • 1
  • 4
  • I had the same error from what appears to be the same cause. I set a pdb trace in the offending method (ImageFile.py, _save @ line 466) and then it worked. I removed the pdb trace and it's still working. Very peculiar. – Carl G Jun 16 '12 at 11:39
  • I realize this is a very belated response to your comment, but I haven't logged on to the site in while. I eventually ended up giving up on doing the progressive Encoding through PIL - it seemed to that the bottom line was it's just too old to handle such large images. – M Barrettara Jul 11 '12 at 15:04

1 Answers1

0

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.

dhilipsiva
  • 3,688
  • 1
  • 24
  • 35