mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-11 17:56:18 +03:00
Use truth value when checking for optimize option on save
This commit is contained in:
parent
508763aa25
commit
d3d29ab2e3
|
@ -688,12 +688,14 @@ def _save(im, fp, filename):
|
|||
progressive = info.get("progressive", False) or\
|
||||
info.get("progression", False)
|
||||
|
||||
optimize = info.get("optimize", False)
|
||||
|
||||
# get keyword arguments
|
||||
im.encoderconfig = (
|
||||
quality,
|
||||
progressive,
|
||||
info.get("smooth", 0),
|
||||
"optimize" in info,
|
||||
optimize,
|
||||
info.get("streamtype", 0),
|
||||
dpi[0], dpi[1],
|
||||
subsampling,
|
||||
|
@ -707,7 +709,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:
|
||||
if optimize 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]
|
||||
|
|
|
@ -696,15 +696,10 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
|
|||
mode = "%s;%d" % (mode, bits)
|
||||
|
||||
# encoder options
|
||||
if "dictionary" in im.encoderinfo:
|
||||
dictionary = im.encoderinfo["dictionary"]
|
||||
else:
|
||||
dictionary = b""
|
||||
|
||||
im.encoderconfig = ("optimize" in im.encoderinfo,
|
||||
im.encoderconfig = (im.encoderinfo.get("optimize", False),
|
||||
im.encoderinfo.get("compress_level", -1),
|
||||
im.encoderinfo.get("compress_type", -1),
|
||||
dictionary)
|
||||
im.encoderinfo.get("dictionary", b""))
|
||||
|
||||
# get the corresponding PNG mode
|
||||
try:
|
||||
|
|
|
@ -126,9 +126,12 @@ class TestFileJpeg(PillowTestCase):
|
|||
|
||||
def test_optimize(self):
|
||||
im1 = self.roundtrip(hopper())
|
||||
im2 = self.roundtrip(hopper(), optimize=1)
|
||||
im2 = self.roundtrip(hopper(), optimize=0)
|
||||
im3 = self.roundtrip(hopper(), optimize=1)
|
||||
self.assert_image_equal(im1, im2)
|
||||
self.assert_image_equal(im1, im3)
|
||||
self.assertGreaterEqual(im1.bytes, im2.bytes)
|
||||
self.assertGreaterEqual(im1.bytes, im3.bytes)
|
||||
|
||||
def test_optimize_large_buffer(self):
|
||||
# https://github.com/python-pillow/Pillow/issues/148
|
||||
|
@ -139,9 +142,14 @@ class TestFileJpeg(PillowTestCase):
|
|||
|
||||
def test_progressive(self):
|
||||
im1 = self.roundtrip(hopper())
|
||||
im2 = self.roundtrip(hopper(), progressive=True)
|
||||
self.assert_image_equal(im1, im2)
|
||||
self.assertGreaterEqual(im1.bytes, im2.bytes)
|
||||
im2 = self.roundtrip(hopper(), progressive=False)
|
||||
im3 = self.roundtrip(hopper(), progressive=True)
|
||||
self.assertFalse(im1.info.get("progressive"))
|
||||
self.assertFalse(im2.info.get("progressive"))
|
||||
self.assertTrue(im3.info.get("progressive"))
|
||||
|
||||
self.assert_image_equal(im1, im3)
|
||||
self.assertGreaterEqual(im1.bytes, im3.bytes)
|
||||
|
||||
def test_progressive_large_buffer(self):
|
||||
f = self.tempfile('temp.jpg')
|
||||
|
|
Loading…
Reference in New Issue
Block a user