TIFF: report correct image size after opening by homm · Pull Request #8387 · python-pillow/Pillow

@homm

@homm

@pre-commit-ci

homm


@property
def size(self) -> tuple[int, int]:
if hasattr(self, "tag_v2"):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a cases after copying or pickling, when the class is actually TiffImageFile, but it is loaded and doesn't have tag_v2 attribute

@homm homm mentioned this pull request

Sep 16, 2024

homm

return super().load()

@property
def size(self) -> tuple[int, int]:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is differ from uploadcare@1d77bfe since for me it looks less magical, but if you can't agree, I can copy the previous as is

@radarhere

@homm

There is no conflict between the presence of eXIf chunks in PNG files and the goal of "having the same size after opening as after loading," because when loading a PNG (by calling the .load() method or any dependent method), the Exif data is populated, but the image is not automatically rotated. This differs from the behavior of TIFF, where calling .load() actually rotates the image and can change its size. This is exactly the issue I aim to address in this PR.

@radarhere

Ah, I see now, thanks.

I think introducing the idea that im.size might not match im._size complicates things. How about #8390 instead?

@hugovk

Closed in favour of #8390.

@hugovk hugovk deleted the tiff-correct-size branch

September 18, 2024 19:35