Fix for issue 2272, CMYK images miss the heuristic for the maxblock buffer scaling

This commit is contained in:
wiredfool 2016-12-03 14:45:45 +00:00
parent 4b57345683
commit 7e2bd28a7c
2 changed files with 10 additions and 1 deletions

View File

@ -716,8 +716,11 @@ def _save(im, fp, filename):
# https://github.com/matthewwithanm/django-imagekit/issues/50
bufsize = 0
if optimize or progressive:
# CMYK can be bigger
if im.mode == 'CMYK':
bufsize = 4 * im.size[0] * im.size[1]
# keep sets quality to 0, but the actual value may be high.
if quality >= 95 or quality == 0:
elif quality >= 95 or quality == 0:
bufsize = 2 * im.size[0] * im.size[1]
else:
bufsize = im.size[0] * im.size[1]

View File

@ -171,6 +171,12 @@ class TestFileJpeg(PillowTestCase):
# this requires more bytes than pixels in the image
im.save(f, format="JPEG", progressive=True, quality=100)
def test_progressive_cmyk_buffer(self):
# Issue 2272, quality 90 cmyk image is tripping the large buffer bug.
f = BytesIO()
im = self.gen_random_image((256,256), 'CMYK')
im.save(f, format='JPEG', progressive=True, quality=94)
def test_large_exif(self):
# https://github.com/python-pillow/Pillow/issues/148
f = self.tempfile('temp.jpg')