1

Its been asked a lot of times how to resize an image and keep the existing exif data. I'm able to do that easily with PIL:

from PIL import Image

im = Image.open("image.jpeg")
exif = im.info['exif']
# process the image, for example resize:
im_resized = im.resize((1920, 1080), resample=PIL.Image.LANCZOS)
im_resized.save("resized.jpeg", quality=70, exif=exif)

I was wondering is there a way to keep the XMP metadata from the original image? There's a lot of GPS data in the XMP which I would love to keep in the resized version.

Dusan
  • 3,284
  • 6
  • 25
  • 46
  • Hi @Dusan. Where you able to solve this somehow? I am at the moment at the same problem – craaaft Jul 31 '21 at 09:22
  • @craaaft - Yes I did. Take a look here: https://dusan-pacal.medium.com/how-i-managed-to-resize-an-image-and-keep-all-the-exif-and-xmp-metadata-using-python-fa68172ee479 – Dusan Aug 05 '21 at 08:03

1 Answers1

0

Not even the successor Pillow can read XMP (and IPTC). Also you're not really keeping anything - you create a whole new file and add a copy of the other EXIF data (including now potentially invalid information like width/height).

JFIF files aren't black magic - their file format can be parsed rather easily; XMP is most likely found in an APP1 segment (just like EXIF). In rare cases it spans over multiple segments. You could first use PIL/Pillow to create your file and then modify it - inserting additional segments is trivial and needs no additional work.

AmigoJack
  • 5,234
  • 1
  • 15
  • 31