import exifread
def get_exif_exifread(image_path):
# 输入图片路径,获取exif
exif = {}
with open(image_path, 'rb') as f:
tags = exifread.process_file(f)
for tag, value in tags.items():
if tag not in ('JPEGThumbnail', 'TIFFThumbnail', 'Filename', 'EXIF MakerNote'):
exif[tag] = str(value)
return exif
def convert_dms(d, m, s):
# 单位换算
dig = d + m / 60 + s / 3600
return dig
def Get_location(file_path):
# 获得经纬度
with open(file_path, 'rb') as f: # 以二进制加载图像
# 返回字典,包含EXIF信息
tags = exifread.process_file(f)
gps_latitude = str(tags.get("GPS GPSLatitude")).split(',')
d = int(gps_latitude[0].replace('[', ''))
m = float(eval(gps_latitude[1]))
s = float(eval(gps_latitude[2].replace(']', '')))
latitude = convert_dms(d, m, s)
gps_longitude = str(tags.get("GPS GPSLongitude")).split(',')
d = int(gps_longitude[0].replace('[', ''))
m = float(eval(gps_longitude[1]))
s = float(eval(gps_longitude[2].replace(']', '')))
longitude = convert_dms(d, m, s)
return longitude, latitude
print(Get_location('test.jpg')) # 将获得元组形式的坐标
---------------------------------------------------------------------------
>>> (118.1107, 24.4303)
可以再加上图片的经纬度,替换默认的时间
参考代码: