Pillow: TypeError on ImageOps.exif_transpose(image)

Created on 29 Nov 2019  路  9Comments  路  Source: python-pillow/Pillow

What did you do?

I was trying to process a dataset on the Detectron2 framework.

What did you expect to happen?

I expected the code to run with no exception.

What actually happened?

TypeError: object of type 'int' has no len()

Here the complete stacktrace:

/home/cezar/Programs/anaconda3/envs/detectron/lib/python3.7/site-packages/PIL/TiffImagePlugin.py:603: UserWarning: Metadata Warning, tag 282 had too many entries: 2, expected 1
  % (tag, len(values))
/home/cezar/Programs/anaconda3/envs/detectron/lib/python3.7/site-packages/PIL/TiffImagePlugin.py:603: UserWarning: Metadata Warning, tag 283 had too many entries: 2, expected 1
  % (tag, len(values))
/home/cezar/Programs/anaconda3/envs/detectron/lib/python3.7/site-packages/PIL/TiffImagePlugin.py:603: UserWarning: Metadata Warning, tag 34853 had too many entries: 9, expected 1
  % (tag, len(values))
Traceback (most recent call last):
  File "test.py", line 21, in <module>
    image = ImageOps.exif_transpose(image)
  File "/home/cezar/Programs/anaconda3/envs/detectron/lib/python3.7/site-packages/PIL/ImageOps.py", line 549, in exif_transpose
    transposed_image.info["exif"] = exif.tobytes()
  File "/home/cezar/Programs/anaconda3/envs/detectron/lib/python3.7/site-packages/PIL/Image.py", line 3213, in tobytes
    return b"Exif\x00\x00" + head + ifd.tobytes(offset)
  File "/home/cezar/Programs/anaconda3/envs/detectron/lib/python3.7/site-packages/PIL/TiffImagePlugin.py", line 837, in tobytes
    count = len(data)
TypeError: object of type 'int' has no len()

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 19.10
  • Python: 3.7.5
  • Pillow: 6.2.1
from PIL import Image, ImageOps
file_name = 'path/to/image/pt59.png'

with open(file_name, "rb") as f:
    image = Image.open(f)
    image = ImageOps.exif_transpose(image)

Here the link to the file:
https://www.dropbox.com/s/z5tc5zddqw20n15/pt59.zip?dl=0
This problem happened to 3 files from the whole dataset, since the images were proprocessed by the same script and taken from the same camera, I don't understand what might be wrong, or if it is a problem on the image or on the PIL library itself.

All 9 comments

4009 helps by changing this error to struct.error: argument out of range.

3980 will fix that remaining error.

Hi! Any ETA on when this makes a release? I'm encountering the very same issue and it's blocking me from releasing to production. Thanks!

Pillow releases quarterly, the next one is due 2020-01-01: https://github.com/python-pillow/Pillow/issues/4210.

3980 has been merged, so this is now resolved. The fix will be available as part of Pillow 7.0

I'm still having the same error on Pillow 7.0.0.

The UserWarning: Metadata Warning, tag 282 had too many entries: 2, expected 1 I mean

@rodrigoruiz do you have an image to demonstrate the warnings, that could be added to the test suite under the Pillow license?

@rodrigoruiz the warning on tag 282 should now be fixed in Pillow master, and will be part of the next Pillow release, due out on July 1.

Did this fix make it into Pillow 7.2.0? It was released June 30, not July 1, so not sure... I've attached a good test photo that triggers the error for me in pillow-simd 7.0.0

White dog looking at camera.jpg.zip

For people who land here and are using pillow-simd, the code in this PR is a solid workaround for this issue if you want to continue to use pillow-simd: https://github.com/facebookresearch/detectron2/pull/1666

Yep, https://github.com/python-pillow/Pillow/pull/4637 was merged on June 10 so made it into 7.2.0.

Was this page helpful?
0 / 5 - 0 ratings