Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageOps.exif_transpose not expected behaviour for TIFF images #7381

Closed
bsekachev opened this issue Sep 7, 2023 · 2 comments · Fixed by #7383
Closed

ImageOps.exif_transpose not expected behaviour for TIFF images #7381

bsekachev opened this issue Sep 7, 2023 · 2 comments · Fixed by #7383

Comments

@bsekachev
Copy link

What did you do?

I have a simple tiff image 150x100px rotated 90 degrees according to exif tag:

sample-out.zip

exiftool -n sample-out.tif
...
Image Width                     : 150
Image Height                    : 100
Orientation                     : 6
...

I tried to rotate the image in Pillow according to EXIF Orientation tag.

What did you expect to happen?

New resolution is 100x150, correct orientation

What actually happened?

New resolution is 150x100, image transposed wrong way

What are your OS, Python and Pillow versions?

  • OS: Ubuntu
  • Python: 3.10
  • Pillow: 9.3.0
from PIL import Image, ImageOps
im = Image.open('sample-out.tif') 
print(im.size) # (150, 100) - correct
im = ImageOps.exif_transpose(im)
print(im.size) # (150, 100) - not correct
im.save('output.tif') # you may save and see that now image rotated 540 degrees and does not contain
exiftool -n output.tif
...
Image Width                     : 150
Image Height                    : 100
# there is not Orientation tag anymore
...

Reason

Image.transpose calls Image.load().
Image.load()calls TiffImageFile.load()
TiffImageFile.load() calls ImageFile.load()
ImageFile.load() calls TiffImageFile.load_end()
load_end() transposes image.

After Image.load() is done, image is transposed again.

@radarhere
Copy link
Member

I've created PR #7383 to resolve this.

@bsekachev
Copy link
Author

@radarhere

Thanks for a quick response :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants