python - How to set exif data in a webp image?

1.1k views Asked by At

I am trying to save an image in Webp format with exif data. Supponsenly I have built libwebp with webpmux support, but even with that, I save the image but not exif data is in.

Can someone help me? It is a code problem or I am reading in a bad way the datas for the new photo.

Code is:

img = PIL.Image.open(imgFile)

exif_dict = piexif.load(img.info["exif"])
exif_bytes = piexif.dump(exif_dict)

img.save(os.path.splitext(imgFile)[0] + '.webp', 'WebP', quality=80, exif=exif_bytes)  # Compress in webp

Thanks in advance.

1

There are 1 answers

0
jjisnow On

I found a bug in piexif where it doesn't save the exif data correctly in webp with img.save, but does with

img.save(os.path.splitext(imgFile)[0] + '.webp', 'WebP', quality=80, exif=exif_bytes)  
piexif.insert(exif_bytes, imgFile)