[Image-SIG] PIL 1.0 (beta?) - Problem saving JPEG

Fredrik Lundh fredrik@pythonware.com
Wed, 15 Dec 1999 13:35:42 +0100

Kingsley Turner <krt@krt.com.au> wrote:
> In the last line of the code, *sometimes* if
> quality=80, the save fails with the error - 
> (depends entirely on the image uploaded)

> Does anyone have a clue as to what might
> be going on here ?

it's probably a bug in PIL (or in the jpeg library, depending
on how you see it).  optimize simply doesn't work well if the
output file is larger than PIL's encoder block size (which is
64k by default).

possible workarounds (besides switching off optimization

1) increase the block size, e.g:

    import ImageFile
    ImageFile.MAXBLOCK = 1000000

2) fall back on an "unoptimized save" if it fails with

    except IOError:
        # try again, without optimization