New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jpeg encoder error with some combination of exif / icc_profile data #1529
Comments
Does the error occur with Pillow 2.9.0?
|
I'm able to reproduce in both master and 2.9.x |
Just as a wild guess, try setting ImageFile.MAXBLOCK to something like 1024*1024 prior to running this. |
@wiredfool - yes, it solves the problem what are the implications of this? in sorl library, they do this: see https://github.com/mariocesar/sorl-thumbnail/blob/master/sorl/thumbnail/engines/pil_engine.py#L209 is it safe to have it changed there to have minimum of 1024*1024? |
This is a long running issue. Essentially, there are a few things that can happen that require that the JpegEncoder be able to process all of something in one shot. The exif is one of those things, It's possible that the iccprofile is another, and in some cases, the entire resulting image needs to fit in the buffer. There's a balance between allocating that buffer every single time and only allocating a larger buffer when it's necessary. MAXBLOCK is the size of the buffer, and I gave you a value to test that was big enough to diagnose the issue. Setting the maxblock to size[0]size[1] is a rough heuristic that may succeed, but may fail for cases where Optimize is true and the Jpeg is not very compressible, since the raw size of the Jpeg is 3size[0]*size[1], since it's a three band image and it's allocating a buffer that's 1/3 of that size. I think we've found that 2_size[0]_size[1] catches those corner cases. But that's only in cases where the JpegDecoder needs to pass back the whole image in one buffer. So it's possible that we've missed a case where the whole image needs to come back, or it's something with the metadata in that image. Since it's only if you update the info, it's likely the metadata. |
I'm getting jpeg encoder error for a specific file. The error occurs if either exif data or icc_profile are in the save params. See below for the image and full code
The bug occurs on either of these:
params.update({'icc_profile': im.info['icc_profile']})
params.update({'exif': im.info['exif']})
But it does not occur for this:
params.update({'icc_profile': im.info['icc_profile'], 'exif': im.info['exif']})
And it does not occur if no params.update is done.
The bug actually occurs in usage of the sorl thumbnail library, but I pinned it down to the following code.
The text was updated successfully, but these errors were encountered: