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

exif_transpose raises TypeError: object of type 'IFDRational' has no len() #7839

Closed
dkbarn opened this issue Feb 28, 2024 · 1 comment · Fixed by #7840
Closed

exif_transpose raises TypeError: object of type 'IFDRational' has no len() #7839

dkbarn opened this issue Feb 28, 2024 · 1 comment · Fixed by #7840
Labels
Bug Any unexpected behavior, until confirmed feature. TIFF

Comments

@dkbarn
Copy link

dkbarn commented Feb 28, 2024

What did you do?

Ran ImageOps.exif_transpose on this image: https://i1.sndcdn.com/avatars-000133622422-vmk8sz-original.jpg

What did you expect to happen?

The image to be transposed

What actually happened?

A TypeError exception was raised:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/share/venv-pillow/lib/python3.10/site-packages/PIL/ImageOps.py", line 641, in exif_transpose
    exif_image.info["exif"] = exif.tobytes()
  File "/share/venv-pillow/lib/python3.10/site-packages/PIL/Image.py", line 3798, in tobytes
    return b"Exif\x00\x00" + head + ifd.tobytes(offset)
  File "/share/venv-pillow/lib/python3.10/site-packages/PIL/TiffImagePlugin.py", line 898, in tobytes
    data = ifd.tobytes(offset)
  File "/share/venv-pillow/lib/python3.10/site-packages/PIL/TiffImagePlugin.py", line 898, in tobytes
    data = ifd.tobytes(offset)
  File "/share/venv-pillow/lib/python3.10/site-packages/PIL/TiffImagePlugin.py", line 907, in tobytes
    "<table: %d bytes>" % len(data) if len(data) >= 16 else str(values)
TypeError: object of type 'IFDRational' has no len()

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 22.04.3
  • Python: 3.10.12
  • Pillow: 10.2.0
import io
from PIL import Image, ImageOps
import requests

response = requests.get("https://i1.sndcdn.com/avatars-000133622422-vmk8sz-original.jpg")
image = Image.open(io.BytesIO(response.content))
ImageOps.exif_transpose(image)
@hugovk hugovk added Bug Any unexpected behavior, until confirmed feature. TIFF labels Feb 28, 2024
@radarhere
Copy link
Member

The problem is the InteropVersion tag. It should have an undefined type, and looking through our test images, it is b'0100' in them.

In your image though, it is 3 rationals. Pillow tries to save it back as undefined, and fails to handle that.

I've created #7840 to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature. TIFF
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants