python-imaging/Pillow — pull request #504 by e98cuenc (2014-01-27 19:33:01+00:00)
Title: Improve heuristic used when saving progressive and optimized JPEGs with high quality values.

The default bufsize used when saving JPEG files with options that require global knowledge (progressive and optimize) is too small in some cases. The result of a too small buffer is:

Suspension not allowed here
....
IOError: encoder error -2 when writing image file

This happens regularly when you try to save with high quality (it depends on the particular pixels of the image, in some cases a bufsize of width * height is ok even for the highest quality).

I'm using a more generous buffer when the quality goes over 94. In my tests random images start using a buffer larger than width * height for qualities >= 95.

Just to be clear, this is not a theoretical bug. I'm seeing it in production when trying to save regular images with quality 100.