python 通過exifread讀取照片信息
通過第三方庫exifread讀取照片信息。exifread官網(wǎng):https://pypi.org/project/ExifRead/
一、安裝exifreadpip install exifread二、讀取照片信息,以及根據(jù)經(jīng)緯度通過百度地圖API獲取位置
import exifreadimport jsonimport urllib.request# Open image file for reading (binary mode)f = open(’001.jpg’, ’rb’)# Return Exif tagstags = exifread.process_file(f)’’’#打印所有照片信息for tag in tags.keys(): print('Key: {}, value {}'.format(tag, tags[tag]))’’’#打印照片其中一些信息print(’拍攝時間:’, tags[’EXIF DateTimeOriginal’])print(’照相機(jī)制造商:’, tags[’Image Make’])print(’照相機(jī)型號:’, tags[’Image Model’])print(’照片尺寸:’, tags[’EXIF ExifImageWidth’], tags[’EXIF ExifImageLength’])#獲取經(jīng)度或緯度def getLatOrLng(refKey, tudeKey): if refKey not in tags: return None ref=tags[refKey].printable LatOrLng=tags[tudeKey].printable[1:-1].replace(' ','').replace('/',',').split(',') LatOrLng=float(LatOrLng[0])+float(LatOrLng[1])/60+float(LatOrLng[2])/float(LatOrLng[3])/3600 if refKey == ’GPS GPSLatitudeRef’ and tags[refKey].printable != 'N': LatOrLng=LatOrLng*(-1) if refKey == ’GPS GPSLongitudeRef’ and tags[refKey].printable != 'E': LatOrLng=LatOrLng*(-1) return LatOrLng#調(diào)用百度地圖API通過經(jīng)緯度獲取位置def getlocation(lat,lng): url = ’http://api.map.baidu.com/geocoder/v2/?location=’ + lat + ’,’ + lng + ’&output=json&pois=1&ak=申請的百度地圖KEY’ req = urllib.request.urlopen(url) res = req.read().decode('utf-8') str = json.loads(res) #print(str) jsonResult = str.get(’result’) formatted_address = jsonResult.get(’formatted_address’) return formatted_addresslat = getLatOrLng(’GPS GPSLatitudeRef’,’GPS GPSLatitude’) #緯度lng = getLatOrLng(’GPS GPSLongitudeRef’,’GPS GPSLongitude’) #經(jīng)度print(’緯度:{} 經(jīng)度:{}’.format(lat, lng))location = getlocation(str(lat), str(lng))print(’位置:{}’.format(location))
以上就是python 通過exifread讀取照片信息的詳細(xì)內(nèi)容,更多關(guān)于python 讀取照片信息的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. 基于 Python 實踐感知器分類算法2. Python如何批量生成和調(diào)用變量3. ASP.Net Core對USB攝像頭進(jìn)行截圖4. ajax動態(tài)加載json數(shù)據(jù)并詳細(xì)解析5. Python 中如何使用 virtualenv 管理虛擬環(huán)境6. python利用opencv實現(xiàn)顏色檢測7. 通過CSS數(shù)學(xué)函數(shù)實現(xiàn)動畫特效8. ASP.Net Core(C#)創(chuàng)建Web站點的實現(xiàn)9. ASP.NET MVC實現(xiàn)橫向展示購物車10. windows服務(wù)器使用IIS時thinkphp搜索中文無效問題
