Skip to content

Bug: TypeError exif_transpose() / exif.tobytes()  #6882

@kxrob

Description

@kxrob

Doing PIL.ImageOps.exif_transpose(im) for a .jpg I get this error:

  File "C:\Python38\lib\site-packages\PIL\ImageOps.py", line 602, in exif_transpose
    transposed_image.info["exif"] = transposed_exif.tobytes()
  File "C:\Python38\lib\site-packages\PIL\Image.py", line 3628, in tobytes
    return b"Exif\x00\x00" + head + ifd.tobytes(offset)
  File "C:\Python38\lib\site-packages\PIL\TiffImagePlugin.py", line 878, in tobytes
    data = ifd.tobytes(offset)
  File "C:\Python38\lib\site-packages\PIL\TiffImagePlugin.py", line 887, in tobytes
    "<table: %d bytes>" % len(data) if len(data) >= 16 else str(values)
TypeError: object of type 'IFDRational' has no len()

At post-mortem:

>>> PIL.__version__
'9.3.0'
>>> data
2.2
>>> type(data)
<class 'PIL.TiffImagePlugin.IFDRational'>
>>> len(data)
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
TypeError: object of type 'IFDRational' has no len()

# stack frame `data = ifd.tobytes(offset)`
>>> tag, value
(34853, {5: 2.2, 6: 0.0})   # GPSInfo
>>> type(value[5])
<class 'PIL.TiffImagePlugin.IFDRational'>

# stack frame with image:
>>> im.getexif()[274]  # Orientation
6

(Can't publish the image / exif unfortunately, but it should be clear whats going on: IFDRational in GPS exif tag fails to serialize to bytes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions