Skip to content

getiptcinfo() fails to get iptc metadata for TIFF images #8923

Closed

Description

@junqfisica

What did you do?

I'm trying to read IPTC metadata from a TIFF image.
A simple example would be:

from PIL import Image
with Image.open(file_path) as im:
     print(getiptcinfo(im))

What did you expect to happen?

The IPTC metadata output

What actually happened?

A TypeError saying a bytes-like object is required, not 'int'

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.12
  • Pillow: 11.0.0

An image that reproduces the error can be found here: test_iptc_metadata.zip. The IPTC metadata in this image was created using both GIMP and Photoshop. However, neither application’s metadata is handled correctly in Pillow version 11.0.0.

This issue does not occur in Pillow version 10.4.0, where the metadata is processed as expected. The problem was likely introduced by a change made in the following line of code, which now returns an int type instead of a bytes type, leading to the error mentioned above.

Previously, in versions before 11.0.0, the line was:

data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]

Activity

  1. changed the title [-]Method getiptcinfo() fails to get iptc metadata for tif images.[/-] [+]getiptcinfo() fails to get iptc metadata for TIFF images[/+] on Apr 23, 2025
  2. radarhere commented on Apr 23, 2025

    @radarhere
    Member

    Hmm. The change you're referring to comes from #8315. I tested the change against https://github.com/python-pillow/Pillow/blob/main/Tests/images/hopper.Lab.tif, and it works fine with this because that image specifies the tag type as UNDEFINED.

    Your image specifies the tag type as LONG. Interestingly, according to https://web.archive.org/web/20240221164915/https://www.awaresystems.be/imaging/tiff/tifftags/iptc.html, this is a mistake that is often made.

  3. radarhere commented on Apr 24, 2025

    @radarhere
    Member

    I've created #8925

    If you'd like an immediate fix, I find that

    from PIL import Image, IptcImagePlugin, TiffImagePlugin
    with Image.open("test_iptc_metadata.tif") as im:
         im.tag_v2.tagtype[TiffImagePlugin.IPTC_NAA_CHUNK] = 7
         print(IptcImagePlugin.getiptcinfo(im))

    works.

  4. junqfisica commented on Apr 24, 2025

    @junqfisica
    Author

    @radarhere Thank you for your quick reply and the info.

    That's interesting about the tag type; however, we have no control over it since the metadata comes from scanners or is added via Photoshop. :). Thank you for your PR fixing this issue.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions