from PIL import Image from PIL.ExifTags import TAGS def testForExif(imgFileName): try: exifDate = {} imgFile = Image.open(imgFileName) # type:Image.Image # imgFile.show() info = imgFile._getexif() # print(imgFileName,info) if info: for (tag, value) in info.items(): decoded = TAGS.get(tag) #print(decoded) exifDate[decoded] = value exiifGPS = exifDate['GPSInfo'] if exiifGPS: print('[*]' + imgFileName + ' contains GPS MetaData') print(f'[+]GPSInfo:{exiifGPS}') #print(f'info:{info}') #print(f'exifData:{exifDate}') except Exception as e: # print(e) pass return if __name__ == '__main__': testForExif('test.jpg')
输出:
[*]test.jpg contains GPS MetaData
[+]GPSInfo:{0: b'\x02\x03\x00\x00'}