You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Saving an image with mode "P" (palette) as TIFF saves a corrupted palette #1147
Pillow (or the built-in libtiff) corrupts the palette when saving a mode P image as TIFF.
I have Pillow-2.7.0-py2.7.egg and Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32.
Simply opening an existing mode P image and saving it as TIFF will exhibit the problem. The first band (R) of the palette seems OK and the G and B bands are garbage. When I use compression="raw" (and therefore libtiff is not used), the palette is OK.
May be related to #718 but I don't get any exception, the original image in memory is OK (only the saved one is corrupted) and the length doesn't change.
Some code to demonstrate the issue would help (even if it's just "Simply opening an existing mode P image and saving it as TIFF will exhibit the problem") Thanks
This makes a correct TIFF: PIL.Image.open("gif.gif").save("tif.tif")
This makes a corrupted TIFF: PIL.Image.open("gif.gif").save("tif.tif", compression="deflate")
As the input file, any ordinary paletted file will do - I just made a screenshot and saved it in Microsoft Paint as GIF. (Can/should I upload a sample as attachment somehow?)
Right -- it's related to the mess that is tiff metadata.
There's a partial fix to that general issue in a PR, but it breaks the existing API. I'm not sure if this particular issue would be fixed, but it should be added as a test case when we disentangle the tiff stuff.
changed the title [-]saving an image with mode "P" (palette) as TIFF saves a corrupted palette[/-][+]Saving an image with mode "P" (palette) as TIFF saves a corrupted palette[/+]on Feb 17, 2018
Activity
aclark4life commentedon Mar 26, 2015
Some code to demonstrate the issue would help (even if it's just "Simply opening an existing mode P image and saving it as TIFF will exhibit the problem") Thanks
vashek commentedon Mar 26, 2015
Yup, sorry.
This makes a correct TIFF:
PIL.Image.open("gif.gif").save("tif.tif")This makes a corrupted TIFF:
PIL.Image.open("gif.gif").save("tif.tif", compression="deflate")As the input file, any ordinary paletted file will do - I just made a screenshot and saved it in Microsoft Paint as GIF. (Can/should I upload a sample as attachment somehow?)
aclark4life commentedon Mar 26, 2015
Thanks, yes you can select or drag images, see below the comment box.
vashek commentedon Mar 26, 2015
In fact, this can easily be demonstrated even without an input file.
This creates a black image:
PIL.Image.new("P", (100,100)).save("empty.tif")This creates a (in my case) blue image:
PIL.Image.new("P", (100,100)).save("empty.tif", compression="lzw")vashek commentedon Mar 26, 2015
Sample gif.gif:
TIFs not supported here, apparently.
vashek commentedon Mar 26, 2015
Here is the corrupted tif.tif: http://ibin.co/1w9kL7bUficR
cgohlke commentedon Mar 27, 2015
For me
Image.new("P", (100,100)).save("empty.tif")segfaults at https://github.com/python-pillow/Pillow/blob/master/libImaging/TiffDecode.c#L341:The colormap is passed to libtiff as
int *while it should beshort *(https://github.com/python-pillow/Pillow/blob/master/encode.c#L760)wiredfool commentedon Mar 27, 2015
Right -- it's related to the mess that is tiff metadata.
There's a partial fix to that general issue in a PR, but it breaks the existing API. I'm not sure if this particular issue would be fixed, but it should be added as a test case when we disentangle the tiff stuff.
[-]saving an image with mode "P" (palette) as TIFF saves a corrupted palette[/-][+]Saving an image with mode "P" (palette) as TIFF saves a corrupted palette[/+]hugovk commentedon Mar 15, 2018
Is this now fixed?
With macOS High Sierra / Python 3.6.5 / Pillow 5.0.0 / libtiff 4.0.9:
radarhere commentedon Nov 19, 2018
I am also unable to replicate with current Pillow. Testing, I find that the segfault was resolved by #1620