This patch allows a JPEG image to be saved with a specific qtables

value (in dictionary format).

Previously, this would throw a TypeError when checking if the qtables
value was actually a preset. By adding an isStringType check, we can
avoid this error.
This commit is contained in:
Chris Sinchok 2014-05-28 17:21:58 -05:00
parent 8a8aec534b
commit 70a50907c2
2 changed files with 8 additions and 1 deletions

View File

@ -498,7 +498,7 @@ def _save(im, fp, filename):
else:
if subsampling in presets:
subsampling = presets[subsampling].get('subsampling', -1)
if qtables in presets:
if isStringType(qtables) and qtables in presets:
qtables = presets[qtables].get('quantization')
if subsampling == "4:4:4":

View File

@ -230,6 +230,13 @@ def test_quality_keep():
assert_no_exception(lambda: im.save(f, quality='keep'))
def test_qtables():
im = Image.open("Images/lena.jpg")
qtables = im.quantization
f = tempfile('temp.jpg')
assert_no_exception(lambda: im.save(f, qtables=qtables, subsampling=0))
def test_junk_jpeg_header():
# https://github.com/python-imaging/Pillow/issues/630
filename = "Tests/images/junk_jpeg_header.jpg"