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

TypeError on ImageOps.exif_transpose(image) #4238

Closed
czrcbl opened this issue Nov 28, 2019 · 9 comments
Closed

TypeError on ImageOps.exif_transpose(image) #4238

czrcbl opened this issue Nov 28, 2019 · 9 comments

Comments

@czrcbl
Copy link

czrcbl commented Nov 28, 2019

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.

@radarhere
Copy link
Member

#4009 helps by changing this error to struct.error: argument out of range.
#3980 will fix that remaining error.

@Mapiarz
Copy link

Mapiarz commented Dec 27, 2019

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!

@hugovk
Copy link
Member

hugovk commented Dec 27, 2019

Pillow releases quarterly, the next one is due 2020-01-01: #4210.

@radarhere
Copy link
Member

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

Mapiarz added a commit to happydogsnyc/Pillow that referenced this issue Jan 28, 2020
The bug: python-pillow#4238
See the bug for 2 PRs that fix the problem.
@rodrigoruiz
Copy link

rodrigoruiz commented May 5, 2020

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

@radarhere
Copy link
Member

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

@radarhere
Copy link
Member

@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.

@amiantos
Copy link

amiantos commented Sep 9, 2020

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: facebookresearch/detectron2#1666

@hugovk
Copy link
Member

hugovk commented Sep 9, 2020

Yep, #4637 was merged on June 10 so made it into 7.2.0.

d-fence added a commit to odoo-dev/odoo that referenced this issue Feb 5, 2021
On odoo.sh, in some circumstances, when uploading an image as attachment
in odoo leads to a blank image thumbnail. The same image was
successfully uploaded in the same odoo version on runbot instance.

After some investigations, it appears that the issue comes from the
python-pillow version used. A few bugs exists [0,1,2] in python-pillow
7.0.0 (packaged in ubuntu Focal) that are now fixed in version 8.1.0
[3,4,5] (packaged in Debian and specified in Odoo requirements.txt),
that causes the `ImageOps.exif_transpose` method to fail.

The present issue can be considered as a corner case as only images with
particular exif tags cause the issue.

The present fix is a simple workaround by first checking the presence of
the orientation tag and using it, we can avoid a call to the
`exif_transpose` method.

opw-2369166

[0] python-pillow/Pillow#4346
[1] python-pillow/Pillow#3973
[2] python-pillow/Pillow#4238
[3] python-pillow/Pillow#4637
[4] python-pillow/Pillow#3980
[5] python-pillow/Pillow#4009
robodoo pushed a commit to odoo/odoo that referenced this issue Feb 5, 2021
On odoo.sh, in some circumstances, when uploading an image as attachment
in odoo leads to a blank image thumbnail. The same image was
successfully uploaded in the same odoo version on runbot instance.

After some investigations, it appears that the issue comes from the
python-pillow version used. A few bugs exists [0,1,2] in python-pillow
7.0.0 (packaged in ubuntu Focal) that are now fixed in version 8.1.0
[3,4,5] (packaged in Debian and specified in Odoo requirements.txt),
that causes the `ImageOps.exif_transpose` method to fail.

The present issue can be considered as a corner case as only images with
particular exif tags cause the issue.

The present fix is a simple workaround by first checking the presence of
the orientation tag and using it, we can avoid a call to the
`exif_transpose` method.

opw-2369166

[0] python-pillow/Pillow#4346
[1] python-pillow/Pillow#3973
[2] python-pillow/Pillow#4238
[3] python-pillow/Pillow#4637
[4] python-pillow/Pillow#3980
[5] python-pillow/Pillow#4009

closes #65584

Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
fw-bot pushed a commit to odoo-dev/odoo that referenced this issue Feb 5, 2021
On odoo.sh, in some circumstances, when uploading an image as attachment
in odoo leads to a blank image thumbnail. The same image was
successfully uploaded in the same odoo version on runbot instance.

After some investigations, it appears that the issue comes from the
python-pillow version used. A few bugs exists [0,1,2] in python-pillow
7.0.0 (packaged in ubuntu Focal) that are now fixed in version 8.1.0
[3,4,5] (packaged in Debian and specified in Odoo requirements.txt),
that causes the `ImageOps.exif_transpose` method to fail.

The present issue can be considered as a corner case as only images with
particular exif tags cause the issue.

The present fix is a simple workaround by first checking the presence of
the orientation tag and using it, we can avoid a call to the
`exif_transpose` method.

opw-2369166

[0] python-pillow/Pillow#4346
[1] python-pillow/Pillow#3973
[2] python-pillow/Pillow#4238
[3] python-pillow/Pillow#4637
[4] python-pillow/Pillow#3980
[5] python-pillow/Pillow#4009

X-original-commit: b83c48d
fw-bot pushed a commit to odoo-dev/odoo that referenced this issue Feb 5, 2021
On odoo.sh, in some circumstances, when uploading an image as attachment
in odoo leads to a blank image thumbnail. The same image was
successfully uploaded in the same odoo version on runbot instance.

After some investigations, it appears that the issue comes from the
python-pillow version used. A few bugs exists [0,1,2] in python-pillow
7.0.0 (packaged in ubuntu Focal) that are now fixed in version 8.1.0
[3,4,5] (packaged in Debian and specified in Odoo requirements.txt),
that causes the `ImageOps.exif_transpose` method to fail.

The present issue can be considered as a corner case as only images with
particular exif tags cause the issue.

The present fix is a simple workaround by first checking the presence of
the orientation tag and using it, we can avoid a call to the
`exif_transpose` method.

opw-2369166

[0] python-pillow/Pillow#4346
[1] python-pillow/Pillow#3973
[2] python-pillow/Pillow#4238
[3] python-pillow/Pillow#4637
[4] python-pillow/Pillow#3980
[5] python-pillow/Pillow#4009

X-original-commit: b83c48d
fw-bot pushed a commit to odoo-dev/odoo that referenced this issue Feb 5, 2021
On odoo.sh, in some circumstances, when uploading an image as attachment
in odoo leads to a blank image thumbnail. The same image was
successfully uploaded in the same odoo version on runbot instance.

After some investigations, it appears that the issue comes from the
python-pillow version used. A few bugs exists [0,1,2] in python-pillow
7.0.0 (packaged in ubuntu Focal) that are now fixed in version 8.1.0
[3,4,5] (packaged in Debian and specified in Odoo requirements.txt),
that causes the `ImageOps.exif_transpose` method to fail.

The present issue can be considered as a corner case as only images with
particular exif tags cause the issue.

The present fix is a simple workaround by first checking the presence of
the orientation tag and using it, we can avoid a call to the
`exif_transpose` method.

opw-2369166

[0] python-pillow/Pillow#4346
[1] python-pillow/Pillow#3973
[2] python-pillow/Pillow#4238
[3] python-pillow/Pillow#4637
[4] python-pillow/Pillow#3980
[5] python-pillow/Pillow#4009

X-original-commit: b83c48d
fw-bot pushed a commit to odoo-dev/odoo that referenced this issue Feb 5, 2021
On odoo.sh, in some circumstances, when uploading an image as attachment
in odoo leads to a blank image thumbnail. The same image was
successfully uploaded in the same odoo version on runbot instance.

After some investigations, it appears that the issue comes from the
python-pillow version used. A few bugs exists [0,1,2] in python-pillow
7.0.0 (packaged in ubuntu Focal) that are now fixed in version 8.1.0
[3,4,5] (packaged in Debian and specified in Odoo requirements.txt),
that causes the `ImageOps.exif_transpose` method to fail.

The present issue can be considered as a corner case as only images with
particular exif tags cause the issue.

The present fix is a simple workaround by first checking the presence of
the orientation tag and using it, we can avoid a call to the
`exif_transpose` method.

opw-2369166

[0] python-pillow/Pillow#4346
[1] python-pillow/Pillow#3973
[2] python-pillow/Pillow#4238
[3] python-pillow/Pillow#4637
[4] python-pillow/Pillow#3980
[5] python-pillow/Pillow#4009

X-original-commit: b83c48d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants