diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index 7b40d5d4f..fbf4248d9 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -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": diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 43ed55969..58fbb5cc8 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -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-pillow/Pillow/issues/630 filename = "Tests/images/junk_jpeg_header.jpg"