0

I am resizing an image using PIL but the EXIF info is not getting preserved. I was going through answers in stack overflow but all are very old answers and dont seem to be working now. All are using pyexiv2 but I cant find it on google. Can someone suggest some method /to do the above in python 2.7?

def imageresize(srcfile, destfile, newwid):
    img = Image.open(srcfile)
    print img
    s = img.size 
    ratio = (float(newwid)/s[0])
    newhght = int(ratio*s[1])
    img.resize((newwid, newhght),Image.ANTIALIAS)
    img.save(destfile)
user46663
  • 11
  • 1
  • 3
  • 8
  • why not read the EXIF information from the source image and write it to the destination image? – sid-m Oct 22 '17 at 13:23
  • I am not able to get a suitable library to read and write EXIF info. Can you suggest @sid-m – user46663 Oct 22 '17 at 13:58
  • this might help https://stackoverflow.com/questions/4764932/in-python-how-do-i-read-the-exif-data-for-an-image – sid-m Oct 22 '17 at 14:32
  • @sid-m It is very helpful for reading EXIF tags but how do I write back the EXIF tags into the resized image with all tags same except for the width and height tags? – user46663 Oct 22 '17 at 18:43

1 Answers1

0
if "exif" in img.info:
    img.save(destfile, exif=img.info["exif"])
else:
    img.save(destfile)

Or use Piexif.

hMatoba
  • 519
  • 4
  • 7