Use transposed size after opening for TIFF images#8390
Use transposed size after opening for TIFF images#8390hugovk merged 5 commits intopython-pillow:mainfrom
Conversation
|
|
||
| def load_prepare(self) -> None: | ||
| # create image memory if necessary | ||
| if self._im is None or self.im.mode != self.mode or self.im.size != self.size: |
There was a problem hiding this comment.
Not sure how it affects multipage images with different page sizes
There was a problem hiding this comment.
When seeking to a different TIFF frame, self.im is populated afresh.
Pillow/src/PIL/TiffImagePlugin.py
Lines 1189 to 1198 in 08d9c89
There was a problem hiding this comment.
Yeah, I saw this and tried to remove this initialization and relay on load_prepare instead, for some reasons it didn't work.
For me providing correct canvas (self.im) in the base class is more preferable than recreating it in the plugin. There was another approach which doesn't introduce difference between im.size and im._size.
There was a problem hiding this comment.
Ah, I see now - my load_prepare() would create a new core image when the image was loaded after seek().
I've pushed a commit following your other approach.
Co-authored-by: Alexander Karpinsky <[email protected]>
3ab41ec to
a92dca6
Compare
Alternative to #8387
At the moment,
load()might change the size of a TIFF image, since TIFF images are automatically transposed when doing so.load()is a method that many users are probably not even aware of, and so they might findunexpected.
After this PR, the first
im.sizewill also be (590, 88). This has means that changes from #6186 and #6190 can be removed.#8387 solves this by making
im.sizesometimes different toim._size. I would like to avoid that, and have instead found a solution by addingTiffImageFile.load_prepare().While we are here streamlining things so that an image does not change its size after loading, I've also updated ImageFile to remove an implication that loading might change an image's mode.