mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Improve heuristic used when saving progressive and optimized JPEGs with high quality values.
This commit is contained in:
parent
e1489d7c76
commit
bab068a337
|
@ -566,7 +566,10 @@ def _save(im, fp, filename):
|
|||
# https://github.com/jdriscoll/django-imagekit/issues/50
|
||||
bufsize=0
|
||||
if "optimize" in info or "progressive" in info or "progression" in info:
|
||||
bufsize = im.size[0]*im.size[1]
|
||||
if quality >= 95:
|
||||
bufsize = 2 * im.size[0] * im.size[1]
|
||||
else:
|
||||
bufsize = im.size[0] * im.size[1]
|
||||
|
||||
# The exif info needs to be written as one block, + APP1, + one spare byte.
|
||||
# Ensure that our buffer is big enough
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
from tester import *
|
||||
|
||||
import array
|
||||
import random
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageFile
|
||||
|
||||
|
@ -132,13 +135,21 @@ def test_progressive_large_buffer():
|
|||
im = Image.new("RGB", (4096,4096), 0xff3333)
|
||||
im.save(f, format="JPEG", progressive=True)
|
||||
|
||||
def test_progressive_large_buffer_highest_quality():
|
||||
f = tempfile('temp.jpg')
|
||||
a = array.array('B')
|
||||
a.extend(random.randint(0, 255) for _ in xrange(256 * 256 * 3))
|
||||
im = Image.frombuffer("RGB", (256, 256), a, "raw", "RGB", 0, 1)
|
||||
# this requires more bytes than pixels in the image
|
||||
im.save(f, format="JPEG", progressive=True, quality=100)
|
||||
|
||||
def test_large_exif():
|
||||
#https://github.com/python-imaging/Pillow/issues/148
|
||||
f = tempfile('temp.jpg')
|
||||
im = lena()
|
||||
im.save(f,'JPEG', quality=90, exif=b"1"*65532)
|
||||
|
||||
def test_progressive():
|
||||
def test_progressive_compat():
|
||||
im1 = roundtrip(lena())
|
||||
im2 = roundtrip(lena(), progressive=1)
|
||||
im3 = roundtrip(lena(), progression=1) # compatibility
|
||||
|
|
Loading…
Reference in New Issue
Block a user