Skip to content

Failed to write customized tag into Tiff file #2745

Description

@tymiao1220

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.

Activity

  1. wiredfool commented on Sep 19, 2017

    @wiredfool
    Member

    Unfortunately, Tiff IFD tags are a bit of a mess when writing.

    The native python tiff writer will write arbitrary tags, but it's limited to raw, uncompressed pixel data. The libtiff writer is limited to only the standard builtin tags, and at that, only a subset. We do not currently implement the api methods required to do arbitrary metadata through libtiff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions