国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python讀取圖片EXIF信息類庫介紹和使用實例

2019-11-25 18:19:57
字體:
來源:轉載
供稿:網友

首先要介紹的是 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之外,還有許多類庫可供使用:

Media Metadata for Python

EXIF.py

Python Exif Parser

A Blogger's Exif Parser

pyexiv2


接著看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)

其他類庫請自行研究。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桃园县| 大足县| 札达县| 海南省| 治县。| 外汇| 登封市| 蚌埠市| 秀山| 诸暨市| 靖宇县| 固阳县| 晋州市| 拉萨市| 平乐县| 东山县| 浮山县| 和田市| 襄城县| 绵竹市| 博兴县| 中阳县| 蓬溪县| 莎车县| 靖宇县| 东辽县| 平定县| 洪泽县| 高邮市| 观塘区| 苗栗县| 平江县| 揭西县| 顺昌县| 满城县| 阳春市| 会宁县| 颍上县| 勃利县| 宜丰县| 潮州市|