def exifread_infos(photo): import exifread #加載 ExifRead 第三方庫 https://pypi.org/project/ExifRead/ #獲取照片時間、經緯度信息 #photo參數:照片文件路徑 # Open image file for reading (binary mode) f = open(photo, 'rb') # Return Exif tags tags = exifread.process_file(f) try: #拍攝時間 EXIF_Date=tags["EXIF DateTimeOriginal"].printable #緯度 LatRef=tags["GPS GPSLatitudeRef"].printable Lat=tags["GPS GPSLatitude"].printable[1:-1].replace(" ","").replace("/",",").split(",") Lat=float(Lat[0])+float(Lat[1])/60+float(Lat[2])/float(Lat[3])/3600 if LatRef != "N": Lat=Lat*(-1) #經度 LonRef=tags["GPS GPSLongitudeRef"].printable Lon=tags["GPS GPSLongitude"].printable[1:-1].replace(" ","").replace("/",",").split(",") Lon=float(Lon[0])+float(Lon[1])/60+float(Lon[2])/float(Lon[3])/3600 if LonRef!="E": Lon=Lon*(-1) f.close() except : return "ERROR:請確保照片包含經緯度等EXIF信息。" else: return EXIF_Date,Lat,Lon