Merge pull request #2115 from radarhere/progressive

Read value when checking for JPEG progressive key
This commit is contained in:
wiredfool 2016-09-23 15:40:08 +01:00 committed by GitHub
commit a490b66335
2 changed files with 18 additions and 7 deletions

View File

@ -682,13 +682,16 @@ def _save(im, fp, filename):
o8(len(markers)) + marker)
i += 1
# "progressive" is the official name, but older documentation
# says "progression"
# FIXME: issue a warning if the wrong form is used (post-1.1.7)
progressive = info.get("progressive", False) or\
info.get("progression", False)
# get keyword arguments
im.encoderconfig = (
quality,
# "progressive" is the official name, but older documentation
# says "progression"
# FIXME: issue a warning if the wrong form is used (post-1.1.7)
"progressive" in info or "progression" in info,
progressive,
info.get("smooth", 0),
"optimize" in info,
info.get("streamtype", 0),
@ -704,7 +707,7 @@ def _save(im, fp, filename):
# channels*size, this is a value that's been used in a django patch.
# https://github.com/matthewwithanm/django-imagekit/issues/50
bufsize = 0
if "optimize" in info or "progressive" in info or "progression" in info:
if "optimize" in info or progressive:
# keep sets quality to 0, but the actual value may be high.
if quality >= 95 or quality == 0:
bufsize = 2 * im.size[0] * im.size[1]

View File

@ -227,12 +227,20 @@ class TestFileJpeg(PillowTestCase):
def test_progressive_compat(self):
im1 = self.roundtrip(hopper())
self.assertFalse(im1.info.get("progressive"))
self.assertFalse(im1.info.get("progression"))
im2 = self.roundtrip(hopper(), progressive=0)
im3 = self.roundtrip(hopper(), progression=0) # compatibility
self.assertFalse(im2.info.get("progressive"))
self.assertFalse(im2.info.get("progression"))
self.assertFalse(im3.info.get("progressive"))
self.assertFalse(im3.info.get("progression"))
im2 = self.roundtrip(hopper(), progressive=1)
im3 = self.roundtrip(hopper(), progression=1) # compatibility
self.assert_image_equal(im1, im2)
self.assert_image_equal(im1, im3)
self.assertFalse(im1.info.get("progressive"))
self.assertFalse(im1.info.get("progression"))
self.assertTrue(im2.info.get("progressive"))
self.assertTrue(im2.info.get("progression"))
self.assertTrue(im3.info.get("progressive"))