Python-根據照片信息獲取用戶詳細信息(微信發原圖或泄露位置信息)


前言

本文的文字及圖片來源於網絡,僅供學習、交流使用,不具有任何商業用途,版權歸原作者所有,如有問題請及時聯系我們以作處理。

作者: 蒙娜麗胖

PS:如有需要Python學習資料的小伙伴可以加點擊下方鏈接自行獲取

http://note.youdao.com/noteshare?id=3054cce4add8a909e784ad934f956cef

前言

有媒體曝出,微信發原圖或存在泄露位置信息的風險。 對此,騰訊微信團隊微博12月1日發布聲明稱,朋友圈發送的照片都經過系統自動壓縮,不帶位置等信息,實在擔心的話,可以P完圖再發,如下圖:

在這里插入圖片描述

微信團隊提到過Exif,何為Exif?

可交換圖像文件格式(英語:Exchangeable image file format,官方簡稱Exif),是專門為數碼相機的照片設定的,可以記錄數碼照片的屬性信息和拍攝數據。

Exif最初由日本電子工業發展協會在1996年制定,版本為1.0。1998年,升級到2.1,增加了對音頻文件的支持。2002年3月,發表了2.2版。

Python庫

這里需要Python的兩個庫,一個是讀取Exif信息的exifread;一個是根據經緯度獲取詳細地址信息的geopy;

安裝如下:

pip3 install exifread
​
pip3 install geopy

 

Python源碼

 1 import exifread
 2 import json
 3 import urllib.request
 4 import sys
 5 from geopy.geocoders import Nominatim
 6  7 # 獲取照片的詳細信息
 8 def get_img_infor_tup(photo):
 9     img_file = open(photo, 'rb')
10     image_map = exifread.process_file(img_file)
11 12     try:
13         #圖片的經度
14         img_longitude_ref = image_map["GPS GPSLongitudeRef"].printable
15         img_longitude = image_map["GPS GPSLongitude"].printable[1:-1].replace(" ","").replace("/",",").split(",")
16         img_longitude = float(img_longitude[0])+float(img_longitude[1])/60+float(img_longitude[2])/float(img_longitude[3])/3600
17         if img_longitude_ref != "E":
18             img_longitude = img_longitude * (-1)
19 20         #圖片的緯度
21         img_latitude_ref = image_map["GPS GPSLatitudeRef"].printable
22         img_latitude = image_map["GPS GPSLatitude"].printable[1:-1].replace(" ","").replace("/",",").split(",")
23         img_latitude = float(img_latitude[0])+float(img_latitude[1])/60+float(img_latitude[2])/float(img_latitude[3])/3600
24         if img_latitude_ref != "N":
25             img_latitude = img_latitude*(-1)
26 27         #照片拍攝時間
28         img_create_date = image_map["EXIF DateTimeOriginal"].printable
29 30         img_file.close()
31 32         # 返回經緯度元組
33         return img_longitude, img_latitude, img_create_date
34 35     except Exception as e:
36         print('ERROR:圖片中不包含Gps信息')
37 38 # 根據經緯度獲取詳細的信息
39 def get_detail_infor(lat, lon):
40     reverse_value = str(lat) + ', ' + str(lon)
41     geolocator = Nominatim()
42     location = geolocator.reverse(reverse_value)
43 44     print('照片的經緯度信息:')
45     print((location.latitude, location.longitude))
46 47     print('照片的地址信息:')
48     print(location.address)
49     
50     print('照片的全部信息:')
51     print(location.raw)
52 53 if __name__ == '__main__':
54     infor_tup = get_img_infor_tup('./image/IMG_2174.JPG')
55     get_detail_infor(infor_tup[1], infor_tup[0])

 


   

運行結果

1 照片的經緯度信息:
2 (31.2734692, 121.4653229)
3 4 照片的地址信息:
5 Appart Jeje, 45, 柳營路, 卓悅局, 靜安區, 上海市, 200072, China 中國
6 7 照片的全部信息:
8 {'place_id': 245107137, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'node', 'osm_id': 6066843985, 'lat': '31.2734692', 'lon': '121.4653229', 'display_name': 'Appart Jeje, 45, 柳營路, 卓悅局, 靜安區, 上海市, 200072, China 中國', 'address': {'address29': 'Appart Jeje', 'house_number': '45', 'road': '柳營路', 'neighbourhood': '卓悅局', 'city': '靜安區', 'county': '靜安區', 'state': '上海市', 'postcode': '200072', 'country': 'China 中國', 'country_code': 'cn'}, 'boundingbox': ['31.2733692', '31.2735692', '121.4652229', '121.4654229']}

 

結束語

Exif針對所以的原圖照片,所以在發照片的時候如果不想個人信息被泄露,可以發壓縮過得圖片和PS過得圖片,需要說明的一點是通過微信發照片是默認壓縮的!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM