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

Pillow corrupts EXIF after changing it #5273

Closed
andreymal opened this issue Feb 18, 2021 · 2 comments
Closed

Pillow corrupts EXIF after changing it #5273

andreymal opened this issue Feb 18, 2021 · 2 comments
Labels

Comments

@andreymal
Copy link

andreymal commented Feb 18, 2021

I still have a rotated photo (the same as I reported earlier) and I still want to exif_transpose it: https://cdn.everypony.ru/storage/06/18/58/2019/08/19/3e8e6e42ca.jpg

ImageOps.exif_transpose works great, but I want to keep exif as is (except orientation tag, of course):

from PIL import Image, ImageOps
im = Image.open('3e8e6e42ca.jpg')
im2 = ImageOps.exif_transpose(im)
im2.save('3e8e6e42ca_rotated.jpg', exif=im2.info['exif'])

However, I found that some of the tags were gone. It turned out that the exif data is corrupted:

im3 = Image.open('3e8e6e42ca_rotated.jpg')
PIL/TiffImagePlugin.py:793: UserWarning: Corrupt EXIF data.  Expecting to read 12 bytes but only got 11. 

Third-party tools like exiv2 also generate a lot of warnings:

$ exiv2 -u -p e 3e8e6e42ca_rotated.jpg
Error: Directory Photo: IFD entry 47 lies outside of the data buffer.
Warning: Directory Photo, entry 0x0191 has unknown Exif (TIFF) type 1024; setting type size 1.
Error: Offset of directory Photo, entry 0x0191 is out of bounds: Offset = 0x01000302; truncating the entry
Warning: Directory Photo, entry 0x0592 has unknown Exif (TIFF) type 256; setting type size 1.
Error: Directory Photo, entry 0x0592 has invalid size 3187671040*1; skipping entry.
[...]

So I leave this issue here.

If this information matters — Ubuntu 18.04/20.04, Python 3.6/3.8, Pillow 8.1.0

@radarhere radarhere added the Exif label Feb 18, 2021
@radarhere
Copy link
Member

I think this is because Pillow currently flattens the Exif IFD into the rest of the data (see #3973 (comment)), which has started to be addressed in #4947

@radarhere
Copy link
Member

Testing, with #4947, I find that it fixes the Pillow UserWarning you mention, and exiv2 doesn't complain either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants