Python读取图片EXIF信息类库介绍和使用实例


Posted in Python onJuly 10, 2014

首先要介绍的是 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)

其他类库请自行研究。

Python 相关文章推荐
Python实现微信公众平台自定义菜单实例
Mar 20 Python
整理Python中的赋值运算符
May 13 Python
如何准确判断请求是搜索引擎爬虫(蜘蛛)发出的请求
Oct 13 Python
Python中的FTP通信模块ftplib的用法整理
Jul 08 Python
Python实现计算圆周率π的值到任意位的方法示例
May 08 Python
Python判断中文字符串是否相等的实例
Jul 06 Python
Python 3.x 判断 dict 是否包含某键值的实例讲解
Jul 06 Python
Django中的forms组件实例详解
Nov 08 Python
Python多图片合并PDF的方法
Jan 03 Python
Python 通过监听端口实现唯一脚本运行方式
May 05 Python
安装并免费使用Pycharm专业版(学生/教师)
Sep 24 Python
python编写函数注意事项总结
Mar 29 Python
Python采集腾讯新闻实例
Jul 10 #Python
使用wxpython实现的一个简单图片浏览器实例
Jul 10 #Python
Python语言的12个基础知识点小结
Jul 10 #Python
使用Python获取Linux系统的各种信息
Jul 10 #Python
Django中实现一个高性能计数器(Counter)实例
Jul 09 #Python
python实现的登录和操作开心网脚本分享
Jul 09 #Python
python实现的一个火车票转让信息采集器
Jul 09 #Python
You might like
PHP数组无限分级数据的层级化处理代码
2012/12/29 PHP
PHP读取txt文本文件并分页显示的方法
2015/03/11 PHP
滚动条变色 隐藏滚动条与双击网页自动滚屏显示代码
2009/12/28 Javascript
idTabs基于JQuery的根据URL参数选择Tab插件
2012/04/11 Javascript
什么是Node.js?Node.js详细介绍
2014/06/01 Javascript
js生成的验证码的实现与技术分析
2014/09/17 Javascript
详解JavaScript中的自定义事件编写
2016/05/10 Javascript
AngularJS 过滤与排序详解及实例代码
2016/09/14 Javascript
AngularJS入门示例之Hello World详解
2017/01/04 Javascript
Java中int与integer的区别(基本数据类型与引用数据类型)
2017/02/19 Javascript
整理关于Bootstrap排版的慕课笔记
2017/03/29 Javascript
node+koa2+mysql+bootstrap搭建一个前端论坛
2018/05/06 Javascript
vuejs使用axios异步访问时用get和post的实例讲解
2018/08/09 Javascript
React Native 混合开发多入口加载方式详解
2019/09/23 Javascript
vue style width a href动态拼接问题的解决
2020/08/07 Javascript
Python实用日期时间处理方法汇总
2015/05/09 Python
Python3.2中Print函数用法实例详解
2015/05/19 Python
用Python PIL实现几个简单的图片特效
2019/01/18 Python
理想高通滤波实现Python opencv示例
2019/01/30 Python
详解Python学习之安装pandas
2019/04/16 Python
解决python文件双击运行秒退的问题
2019/06/24 Python
python SQLAlchemy 中的Engine详解
2019/07/04 Python
python实现图片中文字分割效果
2019/07/22 Python
python3.7实现云之讯、聚合短信平台的短信发送功能
2019/09/26 Python
Python OrderedDict的使用案例解析
2019/10/25 Python
python实现图片横向和纵向拼接
2020/03/05 Python
浅谈python的elementtree模块处理中文注意事项
2020/03/06 Python
python使用多线程+socket实现端口扫描
2020/05/28 Python
IE滤镜与CSS3效果(详细整理分享)
2013/01/25 HTML / CSS
Etam德国:内衣精品店
2019/08/25 全球购物
英国网上电器商店:Electricshop
2020/03/15 全球购物
环境科学毕业生自荐信
2013/11/21 职场文书
单位单身证明范本
2014/01/11 职场文书
银行求职信
2014/05/31 职场文书
毕业生应聘求职信
2014/07/10 职场文书
「天才王子的赤字国家重生术」妮妮姆·拉雷粘土人开订
2022/03/21 日漫