two additional tags for saving color images with libtiff

This commit is contained in:
wiredfool 2013-11-05 20:49:09 -08:00
parent ac25dab915
commit d2f1fa0e5f
2 changed files with 33 additions and 0 deletions

View File

@ -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.

View File

@ -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)