-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
Description
What did you do?
Saved a tiff with same exif.
What did you expect to happen?
saved file
What actually happened?
Traceback (most recent call last):
File "/Users/deepio/Desktop/test/ape.py", line 4, in <module>
im.save("testing.tiff", format=im.format, exif=im.getexif().tobytes())
File "/Users/deepio/.pyenv/versions/3.9.13/lib/python3.9/site-packages/PIL/Image.py", line 2353, in save
save_handler(self, fp, filename)
File "/Users/deepio/.pyenv/versions/3.9.13/lib/python3.9/site-packages/PIL/JpegImagePlugin.py", line 747, in _save
exif = exif.tobytes()
File "/Users/deepio/.pyenv/versions/3.9.13/lib/python3.9/site-packages/PIL/Image.py", line 3628, in tobytes
return b"Exif\x00\x00" + head + ifd.tobytes(offset)
File "/Users/deepio/.pyenv/versions/3.9.13/lib/python3.9/site-packages/PIL/TiffImagePlugin.py", line 878, in tobytes
data = ifd.tobytes(offset)
File "/Users/deepio/.pyenv/versions/3.9.13/lib/python3.9/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 'int' has no len()So I traced it:
> /Users/deepio/Desktop/ape.py(11)go()
-> print(im.getexif().tobytes())
(Pdb) b /Users/deepio/.pyenv/versions/3.9.1/lib/python3.9/site-packages/PIL/TiffImagePlugin.py:864
Breakpoint 1 at /Users/deepio/.pyenv/versions/3.9.1/lib/python3.9/site-packages/PIL/TiffImagePlugin.py:864
(Pdb) condition 1 tag==5
New condition set for breakpoint 1.
(Pdb) commands 1
(com) print(f"tag: {tag}\nvalue: {value}")
(com) end
(Pdb) c
tag: 5
value: 0
> /Users/deepio/.pyenv/versions/3.9.1/lib/python3.9/site-packages/PIL/TiffImagePlugin.py(864)tobytes()
-> if tag == STRIPOFFSETS:
(Pdb) is_ifd
False
(Pdb) values = value if isinstance(value, tuple) else (value,)
(Pdb) values
(0,)
(Pdb) self._write_dispatch[typ](self, *values)
0
<same traceback as above>So a possible fix could be to do the same isinstance on data as it is done on values above it.
What are your OS, Python and Pillow versions?
- OS: recreated on MacOS 12.5.1 / Ubuntu 18.04
- Python: (3.9.1/3.9.13)/3.9.9
- Pillow: 9.3.0
from PIL import Image
im = Image.open("38bfc38a_a51a_c735def5ae62.tiff")
# saving is not required to trigger the same failure.
im.getexif().tobytes()