diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index d9525c8d9..fcbcf42ff 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -923,6 +923,9 @@ def _save(im, fp, filename): "tiff_sgilog", "tiff_sgilog24", "tiff_raw_16"] + # required for color libtiff images + ifd[PLANAR_CONFIGURATION] = getattr(im, '_planar_configuration', 1) + # -- multi-page -- skip TIFF header on subsequent pages if not libtiff and fp.tell() == 0: # tiff header (write via IFD to get everything right) @@ -1014,6 +1017,8 @@ def _save(im, fp, filename): blocklist = [STRIPOFFSETS, STRIPBYTECOUNTS, ROWSPERSTRIP, ICCPROFILE] # ICC Profile crashes. atts={} + # bits per sample is a single short in the tiff directory, not a list. + atts[BITSPERSAMPLE] = bits[0] # Merge the ones that we have with (optional) more bits from # the original file, e.g x,y resolution so that we can # save(load('')) == original file. diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 19626c1da..222d403fa 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -179,3 +179,31 @@ def test_g4_string_info(): assert_equal('temp.tif', reread.tag[269]) +def test_blur(): + # test case from irc, how to do blur on b/w image and save to compressed tif. + from PIL import ImageFilter + out = tempfile('temp.tif') + im = Image.open('Tests/images/pport_g4.tif') + im = im.convert('L') + + im=im.filter(ImageFilter.GaussianBlur(4)) + im.save(out, compression='tiff_adobe_deflate') + + im2 = Image.open(out) + im2.load() + + assert_image_equal(im, im2) + + +def test_packbits(): + #im.info['compression']='packbits' + pass + + +def test_cmyk_save(): + im = lena('CMYK') + out = tempfile('temp.tif') + + im.save(out, compression='tiff_adobe_deflate') + im2 = Image.open(out) + assert_image_equal(im, im2)