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实现的DES加密算法和3DES加密算法实例
Jun 03 Python
Python实时获取cmd的输出
Dec 13 Python
Python遍历目录中的所有文件的方法
Jul 08 Python
Python新手入门最容易犯的错误总结
Apr 24 Python
python针对excel的操作技巧
Mar 13 Python
基于Django URL传参 FORM表单传数据 get post的用法实例
May 28 Python
Pandas统计重复的列里面的值方法
Jan 30 Python
django query模块
Apr 20 Python
python获取txt文件词向量过程详解
Jul 05 Python
python with语句的原理与用法详解
Mar 30 Python
pyCharm 实现关闭代码检查
Jun 09 Python
OpenCV中resize函数插值算法的实现过程(五种)
Jun 05 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
Protoss兵种介绍
2020/03/14 星际争霸
人族 TERRAN 概述
2020/03/14 星际争霸
如何解决CI框架的Disallowed Key Characters错误提示
2013/07/05 PHP
PHP封装CURL扩展类实例
2015/07/28 PHP
CodeIgniter针对数据库的连接、配置及使用方法
2016/03/03 PHP
php array_reverse 以相反的顺序返回数组实例代码
2017/04/11 PHP
PHP实现的服务器一致性hash分布算法示例
2018/08/09 PHP
PHP通过GD库实现验证码功能示例
2019/02/23 PHP
PHP中md5()函数的用法讲解
2019/03/30 PHP
php字符串过滤strip_tags()函数用法实例分析
2019/06/24 PHP
项目实践之javascript技巧
2007/12/06 Javascript
Vue.js第四天学习笔记(组件)
2016/12/02 Javascript
javaScript+turn.js实现图书翻页效果实例代码
2017/02/16 Javascript
async/await与promise(nodejs中的异步操作问题)
2017/03/03 NodeJs
Vue实现动态显示textarea剩余字数
2017/05/22 Javascript
Vue中computed与methods的区别详解
2018/03/24 Javascript
详解vue中的computed的this指向问题
2018/12/05 Javascript
layer.js之回调销毁对话框的例子
2019/09/11 Javascript
关于ligerui子页面关闭后,父页面刷新,重新加载的方法
2019/09/27 Javascript
JavaScript实现图片伪异步上传过程解析
2020/04/10 Javascript
Python3.6通过自带的urllib通过get或post方法请求url的实例
2018/05/10 Python
使用python批量读取word文档并整理关键信息到excel表格的实例
2018/11/07 Python
Python中生成一个指定长度的随机字符串实现示例
2019/11/06 Python
pytorch如何冻结某层参数的实现
2020/01/10 Python
html5 迷宫游戏(碰撞检测)实例一
2013/07/25 HTML / CSS
将"引用"作为函数参数有哪些特点
2013/04/05 面试题
教师年终个人自我评价
2013/10/04 职场文书
司法局群众路线教育实践活动开展情况总结
2014/10/25 职场文书
表扬通报怎么写
2015/01/16 职场文书
清洁工个人总结
2015/03/04 职场文书
法制教育观后感
2015/06/17 职场文书
食堂卫生管理制度
2015/08/04 职场文书
CSS中Single Div 绘图技巧的实现
2021/06/18 HTML / CSS
python迷宫问题深度优先遍历实例
2021/06/20 Python
电脑关机速度很慢怎么办 提升电脑关机速度设置教程
2022/04/08 数码科技
Java无向树分析 实现最小高度树
2022/04/09 Javascript