-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
Description
What did you do?
I'm trying to save a TIFF with 'tiff_lzw' compression and an ICC profile. When I set any compression mode other than 'raw' the ICC profile is removed completely. Other TIFF data set through tiffinfo is not stripped away.
What did you expect to happen?
For the output TIFF to have an embedded ICC profile with compression.
What actually happened?
Output TIFF has everything except for ICC profile.
What are your OS, Python and Pillow versions?
- OS: macOS 10.13.6
- Python: 3.7.5
- Pillow: 6.2.1
- LibTIFF: 4.1.0
from PIL import Image, TiffImagePlugin, features
TiffImagePlugin.DEBUG = True
print(f"LibTIFF enabled: {features.check('libtiff')}")
test_image_with_icc = Image.open('test_gm_icc.tiff')
ifd = TiffImagePlugin.ImageFileDirectory_v2()
ifd[TiffImagePlugin.ICCPROFILE] = test_image_with_icc.info.get("icc_profile")
ifd[TiffImagePlugin.ARTIST] = 'Test Artist'
print('--- saving lzw')
test_image_with_icc.save('test_pillow_lzw.tif', compression='tiff_lzw', tiffinfo=ifd)
print('--- saving raw')
test_image_with_icc.save('test_pillow_raw.tif', compression='raw', tiffinfo=ifd)The example above uses an image with ICC profile already embedded, but same happens when I load an external .icc file. LZW drops it and RAW will add it in.
Inspecting LZW file shows tags from original and new tags added through tiffinfo except ICC:
$tiffdump test_pillow_lzw.tif
test_pillow_lzw.tif:
Magic: 0x4949 <little-endian> Version: 0x2a <ClassicTIFF>
Directory 0: offset 47410086 (0x2d36ba6) next 0 (0)
ImageWidth (256) SHORT (3) 1<6000>
ImageLength (257) SHORT (3) 1<4000>
BitsPerSample (258) SHORT (3) 3<8 8 8>
Compression (259) SHORT (3) 1<5>
Photometric (262) SHORT (3) 1<2>
DocumentName (269) ASCII (2) 47<./tests/output/test_200_ ...>
StripOffsets (273) LONG (4) 1<8>
SamplesPerPixel (277) SHORT (3) 1<3>
RowsPerStrip (278) SHORT (3) 1<4000>
StripByteCounts (279) LONG (4) 1<47410078>
XResolution (282) RATIONAL (5) 1<300>
YResolution (283) RATIONAL (5) 1<300>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<2>
PageNumber (297) SHORT (3) 2<2 56752>
Software (305) ASCII (2) 68<GraphicsMagick 1.3.33 20 ...>
Artist (315) ASCII (2) 12<Test Artist\0>
Inspecting RAW version:
$tiffdump test_pillow_raw.tif
test_pillow_raw.tif:
Magic: 0x4949 <little-endian> Version: 0x2a <ClassicTIFF>
Directory 0: offset 8 (0x8) next 0 (0)
ImageWidth (256) LONG (4) 1<6000>
ImageLength (257) LONG (4) 1<4000>
BitsPerSample (258) SHORT (3) 3<8 8 8>
Compression (259) SHORT (3) 1<1>
Photometric (262) SHORT (3) 1<2>
StripOffsets (273) LONG (4) 1<788>
SamplesPerPixel (277) SHORT (3) 1<3>
RowsPerStrip (278) LONG (4) 1<4000>
StripByteCounts (279) LONG (4) 1<72000000>
XResolution (282) RATIONAL (5) 1<300>
YResolution (283) RATIONAL (5) 1<300>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<2>
Artist (315) ASCII (2) 12<Test Artist\0>
ICC Profile (34675) UNDEFINED (7) 560<00 00 0x2 0x30 0x41 0x44 0x42 0x45 0x2 0x10 00 00 0x6d 0x6e 0x74 0x72 0x52 0x47 0x42 0x20 0x58 0x59 0x5a 0x20 ...>
Test file I'm using:
https://github.com/joerambo/files/raw/master/test_gm_icc.tiff