Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

EXIF prefix saved in WebP

Open jjisnow opened this issue 3 years ago • 1 comments

What did you do?

I saved 2 copies of a webp file, one with exif=exif_bytes as shown, one without, then added the exif data by piexif.insert

What did you expect to happen?

exif data to be the same

What actually happened?

winmerge binary comparison reveals "Exif" is quoted one extra time in the Pillow image.save version indicating a coding error

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.8
  • Pillow: 9.2.0


from PIL import Image
import piexif
import piexif.helper

info = "test data in User Comment"
fullfn = "sample_image.webp"

exif_bytes = piexif.dump({
		"Exif": {
			piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(info, encoding="unicode")
		},
	})

with Image.open(fullfn) as image:
	image.save(fullfn, quality=60, exif=exif_bytes)

	image.save("sample_image_inserted_exif.webp", "webp", quality=60)

piexif.insert(exif_bytes, "sample_image_inserted_exif.webp")

jjisnow avatar Sep 15 '22 10:09 jjisnow

I don't think this is an "error". Looking through our test images, flower.webp has the b"Exif\x00\x00" prefix, and flower2.webp does not.

I've created PR #6582 to resolve this, by removing the prefix when saving for the sake of smaller files.

radarhere avatar Sep 15 '22 11:09 radarhere