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操作MySQL数据库具体方法
Oct 28 Python
Python连接PostgreSQL数据库的方法
Nov 28 Python
Python决策树分类算法学习
Dec 22 Python
python提取图像的名字*.jpg到txt文本的方法
May 10 Python
Python UnboundLocalError和NameError错误根源案例解析
Oct 31 Python
详解Python3序列赋值、序列解包
May 14 Python
Python threading的使用方法解析
Aug 28 Python
python编写微信公众号首图思路详解
Dec 13 Python
Python eval函数介绍及用法
Nov 09 Python
详解python中的三种命令行模块(sys.argv,argparse,click)
Dec 15 Python
python工具dtreeviz决策树可视化和模型可解释性
Mar 03 Python
Python学习之时间包使用教程详解
Mar 21 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记录用户通过搜索引擎进网站的关键词
2014/02/13 PHP
php查询ip所在地的方法
2014/12/05 PHP
php实现格式化多行文本为Js可用格式
2015/04/15 PHP
浅谈本地WAMP环境的搭建
2015/05/13 PHP
Codeigniter控制器controller继承问题实例分析
2016/01/19 PHP
Joomla语言翻译类Jtext用法分析
2016/05/05 PHP
用javascript操作xml
2006/11/04 Javascript
Jquery Uploadify多文件上传带进度条且传递自己的参数
2013/08/28 Javascript
js获取url中指定参数值的示例代码
2013/12/14 Javascript
new Date()问题在ie8下面的处理方法
2014/07/31 Javascript
jQuery实现表格颜色交替显示的方法
2015/03/09 Javascript
jquery实现标签上移、下移、置顶
2015/04/26 Javascript
如何利用JS通过身份证号获取当事人的生日、年龄、性别
2016/01/22 Javascript
bootstrap weebox 支持ajax的模态弹出框
2017/02/23 Javascript
JavaScript实现三级联动菜单效果
2017/08/16 Javascript
jQuery实现的简单拖拽功能示例【测试可用】
2018/08/14 jQuery
Node.js搭建WEB服务器的示例代码
2018/08/15 Javascript
在Vue组件中获取全局的点击事件方法
2018/09/06 Javascript
element-ui 时间选择器限制范围的实现(随动)
2019/01/09 Javascript
jQuery实现消息弹出框效果
2019/12/10 jQuery
JS document form表单元素操作完整示例
2020/01/13 Javascript
利用vue3+ts实现管理后台(增删改查)
2020/10/30 Javascript
Python解释执行原理分析
2014/08/22 Python
对python中for、if、while的区别与比较方法
2018/06/25 Python
Python中出现IndentationError:unindent does not match any outer indentation level错误的解决方法
2020/04/18 Python
Python pip 安装与使用(安装、更新、删除)
2019/10/06 Python
python tkinter GUI绘制,以及点击更新显示图片代码
2020/03/14 Python
Jupyter Notebook的连接密码 token查询方式
2020/04/21 Python
HTML5+CSS3绘制锯齿状的矩形
2016/03/01 HTML / CSS
自荐书范文范例
2014/02/13 职场文书
《只有一个地球》教学反思
2014/02/14 职场文书
开学典礼感言
2014/02/16 职场文书
医疗纠纷协议书
2014/04/16 职场文书
单位委托书怎么写
2014/08/02 职场文书
幼师辞职信怎么写
2015/02/27 职场文书
2015年电工工作总结
2015/04/10 职场文书