python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.32k stars 2.23k forks source link

Writing of XMP and EXIF is inconsistent in 11.0.0 due to #8286 #8479

Open maltelorbach opened 1 month ago

maltelorbach commented 1 month ago

What did you do?

I opened/created a new image with XMP and Exif data. I saved the image using save() without passing the XMP/Exif data.

What did you expect to happen?

In Pillow 10.x, the saved image would not contain any metadata (xmp, exif, ...) unless explicitly passed to save().

What actually happened?

In Pillow 11.0.0, the save image contains XMP metadata although I did not pass it to save().

8286 introduced writing XMP data and its behavior changed with earlier versions and is now inconsistent wrt to how writing exif data is handled. I'd expect either all metadata to be written by default or none.

I believe how the default value of xmp/exif are defined makes the difference:

https://github.com/radarhere/Pillow/blob/6e2ebaae2d50302b58ab046257df492493e5e86e/src/PIL/JpegImagePlugin.py#L754

https://github.com/radarhere/Pillow/blob/6e2ebaae2d50302b58ab046257df492493e5e86e/src/PIL/JpegImagePlugin.py#L794

What are your OS, Python and Pillow versions?

Example

from PIL import Image

im = Image.new("RGB", (128, 128))
im.info["xmp"] = b"some data"
im.info["exif"] = b"some more data"
im.save("img_with_metadata.jpg")

inter = Image.open("img_with_metadata.jpg")

if inter.info.get("xmp") == b"some data":
    print("XMP data is present")
else:
    print("XMP data is not present")

if inter.info.get("exif") == b"some more data":
    print("EXIF data is present")
else:
    print("EXIF data is not present")

Running above code with Pillow 10.4.0:

--------------------------------------------------------------------
Pillow 10.4.0
Python 3.12.1 (main, Jan  4 2024, 15:28:04) [GCC 11.4.0]
--------------------------------------------------------------------
XMP data is not present
EXIF data is not present

With Pillow 11.0.0:

--------------------------------------------------------------------
Pillow 11.0.0
Python 3.12.1 (main, Jan  4 2024, 15:28:04) [GCC 11.4.0]
--------------------------------------------------------------------
>>> XMP data is present
>>> EXIF data is not present
radarhere commented 1 month ago

I've created #8483 to resolve this.