hMatoba / Piexif

Exif manipulation with pure python script.
MIT License
367 stars 81 forks source link

KeyError: 'exif' #65

Closed meicuihui closed 6 years ago

meicuihui commented 6 years ago

when i run this code

import piexif
from PIL import Image

fname='C:/Users/Administrator/Desktop/1.png'
img = Image.open(fname)
exif_dict = piexif.load(img.info['exif'])

altitude = exif_dict['GPS'][piexif.GPSIFD.GPSAltitude]
print(altitude)
exif_dict['GPS'][piexif.GPSIFD.GPSAltitude] = (140, 1)
exif_bytes = piexif.dump(exif_dict)
img.save('_%s' % fname, "jpeg", exif=exif_bytes)

crash error flowing

Traceback (most recent call last):
  File "F:/pySpace/changPic.py", line 6, in <module>
    exif_dict = piexif.load(img.info['exif'])
KeyError: 'exif'
hMatoba commented 6 years ago

It looks that "img.info['exif']" throws error.

charisti5676 commented 4 years ago

Not support's png