I am using python version 2.7
I am trying to write some custom tag(37000 in this case) into new tiff file. It is able to read tag from image but when I am trying to write them it is not successfully written.
When I am use pillow 4.1.0 to do that, tag is not added, and then when I tried old version pillow 2.3, tag is added successfully but cannot save image correctly (only blank)
Could you give me some help, I appreciate that!
Here is the testing code:
from PIL import Image, TiffImagePlugin, TiffTags
def test_custom_metadata():
img = Image.open('mytifffile.tif')
img.tag[37000]='my special tag'
info = TiffImagePlugin.ImageFileDirectory()
CustomTagId = 37000
info[CustomTagId] = 'my special tag'
print(img.tag)
Image.DEBUG=True
TiffImagePlugin.WRITE_LIBTIFF = False # Set to True to see it break.
img.save('temp2.tif',tiffinfo= img.tag)
img2 = Image.open('temp2.tif')
print(img2.tag)
test_custom_metadata()
outputs are:
{256: (1703,), 257: (937,), 258: (8,), 259: (5,), 262: (1,), 296: (1,), 273: (8,), 274: (1,), 339: (1,), 277: (1,), 278: (937,), 279: (1849679,), 37000: ('my special tag',), 284: (1,)}
{256: (1703,), 257: (937,), 258: (8,), 259: (5,), 262: (1,), 296: (1,), 273: (8,), 274: (1,), 339: (1,), 277: (1,), 278: (937,), 279: (1849679,), 284: (1,)}
As you can see, 37000: ('my special tag',) is missing.
I doing this because, my original tiff file have some customized tag(51023), and it is 16 bit. So what I want to do is to rescale it to 8 bit which is able to do and keep that tag(51023) and value as it is.
I am using python version 2.7
I am trying to write some custom tag(37000 in this case) into new tiff file. It is able to read tag from image but when I am trying to write them it is not successfully written.
When I am use pillow 4.1.0 to do that, tag is not added, and then when I tried old version pillow 2.3, tag is added successfully but cannot save image correctly (only blank)
Could you give me some help, I appreciate that!
Here is the testing code:
outputs are:
{256: (1703,), 257: (937,), 258: (8,), 259: (5,), 262: (1,), 296: (1,), 273: (8,), 274: (1,), 339: (1,), 277: (1,), 278: (937,), 279: (1849679,), 37000: ('my special tag',), 284: (1,)}{256: (1703,), 257: (937,), 258: (8,), 259: (5,), 262: (1,), 296: (1,), 273: (8,), 274: (1,), 339: (1,), 277: (1,), 278: (937,), 279: (1849679,), 284: (1,)}As you can see,
37000: ('my special tag',)is missing.I doing this because, my original tiff file have some customized tag(51023), and it is 16 bit. So what I want to do is to rescale it to 8 bit which is able to do and keep that tag(51023) and value as it is.