python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.35k stars 2.24k forks source link

TIFF: report correct image size after opening #8387

Closed homm closed 2 months ago

radarhere commented 2 months ago

This PR was created in an effort to ensure that load() does not change the size of an image.

It naturally sounds like a good idea for images to have the same size after opening as after loading. However, Pillow also aims to open an image without loading it, for the sake of performance, and the rotation data might not appear early on in the file.

For the PNG format, https://ftp-osl.osuosl.org/pub/libpng/documents/pngext-1.5.0.html#C.eXIf states

The eXIf chunk may appear anywhere between the IHDR and IEND chunks except between IDAT chunks.

So I don't think it is possible to simultaneously achieve those two goals.

homm commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

Closed in favour of https://github.com/python-pillow/Pillow/pull/8390.