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

Exif information not saved in JPEG Plugin unless explicitly added in save call #6804

Closed
m472 opened this issue Dec 14, 2022 · 1 comment · Fixed by #6819
Closed

Exif information not saved in JPEG Plugin unless explicitly added in save call #6804

m472 opened this issue Dec 14, 2022 · 1 comment · Fixed by #6819

Comments

@m472
Copy link

m472 commented Dec 14, 2022

What did you do?

Open an image, edit it's exif information, save the image and check the metadata.

What did you expect to happen?

I expected the modified exif information to be written. This is exactly what happend when saving the image as a png.

What actually happened?

The exif information was not saved when using the jpg format. It works when explicitly adding the exif parameter to the save call but this requires adding the exif information everywhere save is called (potentially third party code).

This also means that exif information contained in the original image will be removed by loading and saving a JPEG image using PIL. If this is desired the PNG plugin should probably be modified to handle exif information in the same manner as the JPEG plugin, but for my usecase I prefer the way it is handled in PNG.

What are your OS, Python and Pillow versions?

  • OS: Arch Linux with Kernel 6.0.6
  • Python: 3.10.8
  • Pillow: 9.4.0.dev0 (current main branch)
from PIL import Image
from PIL import ExifTags

desc = "My image description"
exif_tag = ExifTags.Base.ImageDescription

img = Image.open("hopper.jpg")


exif = Image.Exif()
exif[exif_tag] = "My image description"

img.info["exif"] = exif

# png plugin does save exif information
img.save("hopper_out.png")
png_exif = Image.open("hopper_out.png").getexif()
assert png_exif != {}
assert png_exif[exif_tag] == desc

# jpeg plugin does not save exif information
img.save("hopper_out.jpg")
jpg_exif = Image.open("hopper_out.jpg").getexif()
assert jpg_exif != {}
assert jpg_exif[exif_tag] == desc
@radarhere
Copy link
Member

As you've noted in your PR #6807, JPEG, TIFF and WebP don't save the EXIF data from info by default (and incidentally, neither does MPO). Only PNG does.

If you don't have strong feelings about it, it would seem less disruptive to change PNG to match the other formats. I've created PR #6819 for this.

hugovk added a commit that referenced this issue Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants