Python讀取圖片EXIF信息類庫介紹和使用實例
首先要介紹的是 Python Imaging Library,使用方法如下:
from PIL import Image
from PIL.ExifTags import TAGS
def get_exif_data(fname):
"""Get embedded EXIF data from image file."""
ret = {}
try:
img = Image.open(fname)
if hasattr( img, '_getexif' ):
exifinfo = img._getexif()
if exifinfo != None:
for tag, value in exifinfo.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
except IOError:
print 'IOERROR ' + fname
return ret
if __name__ == '__main__':
fileName = 'C:/Users/Leyond/Desktop/IMG_20121122_153514.jpg'
exif = get_exif_data(fileName)
print exif
返回的清單如下:
ExifVersion
ComponentsConfiguration
ExifImageWidth
DateTimeOriginal
DateTimeDigitized
ExifInteroperabilityOffset
FlashPixVersion
MeteringMode
LightSource
Flash
FocalLength
41986
ImageDescription
Make
Model
Orientation
YCbCrPositioning
41988
XResolution
YResolution
59932
ExposureTime
ExposureProgram
ColorSpace
41990
ISOSpeedRatings
ResolutionUnit
41987
FNumber
Software
DateTime
ExifImageHeight
ExifOffset
其中59932,是一大串十六進制的字符,不知為啥。除了PIL之外,還有許多類庫可供使用:
A Blogger's Exif Parser
接著看EXIF.PY,使用方法非常簡單:exif.py IMG_20121122_153514.jpg
EXIF ColorSpace (Short): sRGB
EXIF ComponentsConfiguration (Undefined): YCbCr
EXIF DateTimeDigitized (ASCII): 2012:11:22 15:35:14
EXIF DateTimeOriginal (ASCII): 2012:11:22 15:35:14
EXIF DigitalZoomRatio (Ratio): 1
EXIF ExifImageLength (Long): 2560
EXIF ExifImageWidth (Long): 1920
EXIF ExifVersion (Undefined): 0220
EXIF ExposureBiasValue (Signed Ratio): 0
EXIF ExposureMode (Short): Auto Exposure
EXIF ExposureProgram (Short): Portrait Mode
EXIF ExposureTime (Ratio): 1/256
EXIF FNumber (Ratio): 14/5
EXIF Flash (Short): Flash did not fire
EXIF FlashPixVersion (Undefined): 0100
EXIF FocalLength (Ratio): 35
EXIF ISOSpeedRatings (Short): 56
EXIF InteroperabilityOffset (Long): 4810
EXIF LightSource (Short): other light source
EXIF MeteringMode (Short): CenterWeightedAverage
EXIF Padding (Undefined): []
EXIF SceneCaptureType (Short): Portrait
EXIF WhiteBalance (Short): Auto
Image DateTime (ASCII): 2012:11:24 09:44:50
Image ExifOffset (Long): 2396
Image ImageDescription (ASCII):
Image Make (ASCII):
Image Model (ASCII):
Image Orientation (Short): Horizontal (normal)
Image Padding (Undefined): []
Image ResolutionUnit (Short): Pixels/Inch
Image Software (ASCII): Microsoft Windows Photo Viewer 6.1.7600.16385
Image XResolution (Ratio): 72
Image YCbCrPositioning (Short): Co-sited
Image YResolution (Ratio): 72
Thumbnail Compression (Short): JPEG (old-style)
Thumbnail JPEGInterchangeFormat (Long): 4970
Thumbnail JPEGInterchangeFormatLength (Long): 3883
Thumbnail Orientation (Short): Horizontal (normal)
Thumbnail ResolutionUnit (Short): Pixels/Inch
Thumbnail XResolution (Ratio): 72
Thumbnail YCbCrPositioning (Short): Co-sited
Thumbnail YResolution (Ratio): 72
至于Python Exif Parser,好像沒更新很久了,使用方法也很類似:
import exif
photo_path = "somePath\to\a\photo.jpg"
data = exif.parse(photo_path)
其他類庫請自行研究。
- python3 實現(xiàn)爬取TOP500的音樂信息并存儲到mongoDB數(shù)據(jù)庫中
- python爬取cnvd漏洞庫信息的實例
- Python使用pyshp庫讀取shapefile信息的方法
- Python3爬蟲學習之MySQL數(shù)據(jù)庫存儲爬取的信息詳解
- Python實現(xiàn)的查詢mysql數(shù)據(jù)庫并通過郵件發(fā)送信息功能
- Python 模擬員工信息數(shù)據(jù)庫操作的實例
- python用來獲得圖片exif信息的庫實例分析
- 使用python BeautifulSoup庫抓取58手機維修信息
- 基于python3抓取pinpoint應用信息入庫
相關(guān)文章
Python PyQt5實現(xiàn)的簡易計算器功能示例
這篇文章主要介紹了Python PyQt5實現(xiàn)的簡易計算器功能,涉及Python PyQt5事件響應及數(shù)學運算等相關(guān)操作技巧,需要的朋友可以參考下2017-08-08
PyCharm進行Django項目開發(fā)環(huán)境搭建
本文主要介紹了PyCharm進行Django項目開發(fā)環(huán)境搭建,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2025-02-02
Python程序設(shè)計入門(3)數(shù)組的使用
這篇文章主要介紹了Python數(shù)組的使用方法,需要的朋友可以參考下2014-06-06
TensorFlow和keras中GPU使用的設(shè)置操作
這篇文章主要介紹了TensorFlow和keras中GPU使用的設(shè)置操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-05-05
python+appium實現(xiàn)自動化測試的示例代碼
appium是一個開源的測試自動化框架,可以與原生的、混合的和移動的web應用程序使用,本文主要介紹了python+appium實現(xiàn)自動化測試的示例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-01-01
python按比例隨機切分數(shù)據(jù)的實現(xiàn)
這篇文章主要介紹了python按比例隨機切分數(shù)據(jù)的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07
Python獲取時光網(wǎng)電影數(shù)據(jù)的實例代碼
這篇文章主要介紹了Python獲取時光網(wǎng)電影數(shù)據(jù),基本原理是先通過requests庫,通過時光網(wǎng)自帶的電影數(shù)據(jù)API接口,獲取到指定的電影數(shù)據(jù),本文結(jié)合示例代碼給大家介紹的非常詳細,需要的朋友可以參考下2022-09-09

