From 70a50907c293f68ee9787b7663d78cb92291aa1c Mon Sep 17 00:00:00 2001 From: Chris Sinchok Date: Wed, 28 May 2014 17:21:58 -0500 Subject: [PATCH] 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. --- PIL/JpegImagePlugin.py | 2 +- Tests/test_file_jpeg.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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 4871c3fbf..c9ee4eec2 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-imaging/Pillow/issues/630 filename = "Tests/images/junk_jpeg_header.jpg"