Skip to content

Error reading metadata when using Image.getexif().tobytes() #7185

@lyaoworkaccount

Description

@lyaoworkaccount

What did you do?

Using Pillow to read the exif metadata of a jpg image

What did you expect to happen?

Expected the metadata to converted into bytes

What actually happened?

Issue in the tobytes() function reading the metadata

python3.9/site-packages/PIL/TiffImagePlugin.py", line 895, 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.2
  • Python: 3.9.9
  • Pillow: 9.4.0
from io import BytesIO
from pathlib import Path
from PIL import Image

with Path(__file__).with_name("sample.jpg").open("rb") as fp:
    image = Image.open(BytesIO(fp.read())) 
    image.getexif().tobytes()

a whited out 1x1 pixel image with the metadata that has this problem is attached below

sample

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