Just in case, someone would like to use piexiv2, here is the solution: resizing the image using the PIL library, EXIF data copied from pyexiv2, and the sizes of the EXIF fields of the image are set to a new size.
import pyexiv2
import tempfile
from PIL import Image
def resize_image(source_path, dest_path, size):
image = Image.open(source_path)
image.thumbnail(size, Image.ANTIALIAS)
image.save(dest_path, "JPEG")
source_image = pyexiv2.Image(source_path)
source_image.readMetadata()
dest_image = pyexiv2.Image(dest_path)
dest_image.readMetadata()
source_image.copyMetadataTo(dest_image)
dest_image["Exif.Photo.PixelXDimension"] = image.size[0]
dest_image["Exif.Photo.PixelYDimension"] = image.size[1]
dest_image.writeMetadata()
resize_image("41965749.jpg", "resized.jpg", (600,400))
source
share