镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Error saving and loading TIFF with exif with version>10.1 #8038

Closed

Description

@MatthieuCMira

Hi,

I manage a library for geoscientific data. We use PIL to generate and load TIFF images, storing the coordinates of our TIFF images in the EXIF data. However, since version 10.2, the methods we were using no longer function properly and cause bugs. We are temporarily fixing the PIL version to 10.1 to avoid these issues.

Here are the details of the issue we are encountering:

Pillow 10.3
Windows 10
Python 3.10

Steps to reproduce the error:

    tag = {
        256: (128,),
        257: (128,),
        258: (8, 8, 8),
        259: (1,),
        33922: (0.0, 0.0, 0.0, 522796.33210329525, 7244067.563364625, 0.0),
        42113: ("255",),
        262: (2,),
        33550: (0.9990415797117552, 0.999041579711816, 0.0),
        339: (1, 1, 1),
        277: (3,),
        278: (5,),
        284: (1,),
        34737: ("WGS 84 / UTM zone 34N|WGS 84|",),
    }

    # create and save a tiff
    image = Image.fromarray(
        np.random.randint(0, 255, (128, 128, 3)).astype("uint8"), "RGB"
    )

    for id_ in tag.items():
        image.getexif()[id_[0]] = id_[1]

    # image.save("testtif.tif", exif=image.getexif())  # was working with 10.1
    image.save("testtif.tif", exif=image.getexif(), compression='tiff_deflate')  # for 10.3

    image = Image.open("testtif.tif")  # was working with 10.1

Is this behaviour a bug or an intended change in the API? Are there some specific options or settings that could serve as a workaround?

Thank you!

Activity

  1. Yay295 commented on May 1, 2024

    @Yay295
    Contributor

    Not related to your issue, but fyi there's an ExifTags module you can use. https://github.com/python-pillow/Pillow/blob/main/src/PIL/ExifTags.py

    so instead of

    tag = {
        256: (128,),
        ...
    }

    you can do

    from PIL import ExifTags
    tag = {
        ExifTags.Base.ImageWidth: (128,),
        ...
    }
  2. changed the title [-]Error save an load tiff image with exif with version>10.1 (TiffImagePlugin)[/-] [+]Error save an load tiff image with exif with version>10.1[/+] on May 1, 2024
  3. radarhere commented on May 1, 2024

    @radarhere
    Member

    The error you're experiencing is NotImplementedError: multistrip support not yet implemented, yes?

    This has started happening for you because of #7654. It allowed the user to set the ROWSPERSTRIP tag, number 278. You're providing (5,) for that tag. The error is being triggered because 5 is smaller than 128, the height of your image, and as the error says, we have not yet implemented multistrip support.

    The simplest solution would be to just remove 278 from your tag dictionary.

  4. changed the title [-]Error save an load tiff image with exif with version>10.1[/-] [+]Error saving and loading TIFF with exif with version>10.1[/+] on May 1, 2024
  5. MatthieuCMira commented on May 1, 2024

    @MatthieuCMira
    Author

    The error you're experiencing is NotImplementedError: multistrip support not yet implemented, yes?

    This has started happening for you because of #7654. It allowed the user to set the ROWSPERSTRIP tag, number 278. You're providing (5,) for that tag. The error is being triggered because 5 is smaller than 128, the height of your image, and as the error says, we have not yet implemented multistrip support.

    The simplest solution would be to just remove 278 from your tag dictionary.

    Yes, you're right it worked.

    It solves my problem if I don't use compression="tiff_deflate.  

    Thank you very much! 

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