源码传送门
环境准备
下面的两个第三方模块都可以直接通过pip快速安装,这里使用py36作为运行环境。
python3.6 requests exifread思路
基础知识
下面是现今相片中会存在与GPS相关的关键字,大牛亦可一比带过~ [参考]
{ "GPSVersionID": "GPS版本", "GPSLatitudeRef": "南北纬", "GPSLatitude": "纬度", "GPSLongitudeRef": "东西经", "GPSLongitude": "经度", "GPSAltitudeRef": "海拔参照值", "GPSAltitude": "海拔", "GPSTimeStamp": "GPS时间戳", "GPSSatellites": "测量的卫星", "GPSStatus": "接收器状态", "GPSMeasureMode": "测量模式", "GPSDOP": "测量精度", "GPSSpeedRef": "速度单位", "GPSSpeed": "GPS接收器速度", "GPSTrackRef": "移动方位参照", "GPSTrack": "移动方位", "GPSImgDirectionRef": "图像方位参照", "GPSImgDirection": "图像方位", "GPSMapDatum": "地理测量资料", "GPSDestLatitudeRef": "目标纬度参照", "GPSDestLatitude": "目标纬度", "GPSDestLongitudeRef": "目标经度参照", "GPSDestLongitude": "目标经度", "GPSDestBearingRef": "目标方位参照", "GPSDestBearing": "目标方位", "GPSDestDistanceRef": "目标距离参照", "GPSDestDistance": "目标距离", "GPSProcessingMethod": "GPS处理方法名", "GPSAreaInformation": "GPS区功能变数名", "GPSDateStamp": "GPS日期", "GPSDifferential": "GPS修正"}
初始化
考虑到exifread的模块中有大量的logging输出,这里将它的level级别调到最高。 然后下边的KEY是某站在高德地图API的时候遗留下来的 我也很尴尬。。就当福利了
import osimport timeimport jsonimport randomimport loggingimport requestsimport exifreadlogging.basicConfig(level=logging.CRITICAL)KEY = "169d2dd7829fe45690fabec812d05bc3"
主逻辑函数
def main(): # 预设后缀列表 types = ["bmp", "jpg", "tiff", "gif", "png"] #结果数据集合 picex = [] # 文件存储路径 saves = "$" + input("| SavePath: ").strip() # 文件搜索路径 并遍历所有文件返回文件路径列表 pools = jpgwalk(input("| FindPath: "), types) #存储目录 savep = "%s/%s" % (os.getcwd().replace("//", "/"), saves) if savep in pools: pools.remove(savep) # 遍历数据集并获取exif信息 for path in pools: res = getEXIF(path) if res: picex.append(res) # 结果报告 print("| Result %s" % len(picex)) # 如果存在结果 保存结果到json并讲相关图片复制到该目录下 if picex: #创建目录 if not os.path.exists(saves): os.mkdir(saves) #生成一个4格缩进的json文件 with open("%s/%s.json" % (saves, saves), "wb") as f: f.write(json.dumps(picex, ensure_ascii=False, indent=4).encode("utf8")) #copy图像到该目录 for item in picex: source_path = item["Filename"] with open("%s/%s" % (saves, source_path.split("/")[-1]), "wb") as f_in: with open(source_path, "rb") as f_out: f_in.write(f_out.read())
新闻热点
疑难解答