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存取XML的常见方法实例分析
Mar 21 Python
使用Python对Excel进行读写操作
Mar 30 Python
Python解决抛小球问题 求小球下落经历的距离之和示例
Feb 01 Python
Python打印输出数组中全部元素
Mar 13 Python
python3利用tcp实现文件夹远程传输
Jul 28 Python
Python利用字典破解WIFI密码的方法
Feb 27 Python
Django如何简单快速实现PUT、DELETE方法
Jul 24 Python
在Python中使用MySQL--PyMySQL的基本使用方法
Nov 19 Python
Python实现数值积分方式
Nov 20 Python
Python join()函数原理及使用方法
Nov 14 Python
Python 实现集合Set的示例
Dec 21 Python
详解如何修改jupyter notebook的默认目录和默认浏览器
Jan 24 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 冒泡排序 交换排序法
2011/05/10 PHP
php 深入理解strtotime函数的使用详解
2013/05/23 PHP
解析php php_openssl.dll的作用
2013/07/01 PHP
destoon实现会员商铺中指定会员或会员组投放广告的方法
2014/08/21 PHP
是 WordPress 让 PHP 更流行了 而不是框架
2016/02/03 PHP
php使用file函数、fseek函数读取大文件效率对比分析
2016/11/04 PHP
Yii2下session跨域名共存的解决方案
2017/02/04 PHP
浅谈Laravel核心解读之Console内核
2018/12/02 PHP
PHP创建XML的方法示例【基于DOMDocument类及SimpleXMLElement类】
2019/09/10 PHP
Jqgrid表格随窗口大小改变而改变的简单实例
2013/12/28 Javascript
window.onload与$(document).ready()的区别分析
2015/05/30 Javascript
jQuery实现带滑动条的菜单效果代码
2015/08/26 Javascript
基于JS2Image实现圣诞树代码
2015/12/24 Javascript
前端学习笔记style,currentStyle,getComputedStyle的用法与区别
2016/05/28 Javascript
实例解析Array和String方法
2016/12/14 Javascript
Node.js自定义实现文件路由功能
2017/09/22 Javascript
一步步教你利用webpack如何搭一个vue脚手架(超详细讲解和注释)
2018/01/08 Javascript
Angular6 用户自定义标签开发的实现方法
2019/01/08 Javascript
vue-cli+axios实现文件上传下载功能(下载接收后台返回文件流)
2019/05/10 Javascript
jquery将json转为数据字典的实例代码
2019/10/11 jQuery
借助云开发实现小程序短信验证码的发送
2020/01/06 Javascript
微信小程序调用wx.getImageInfo遇到的坑解决
2020/05/31 Javascript
python对excel文档去重及求和的实例
2018/04/18 Python
python求质数的3种方法
2018/09/28 Python
Django生成PDF文档显示网页上以及PDF中文显示乱码的解决方法
2019/12/17 Python
Python networkx包的实现
2020/02/14 Python
CSS3 实现的缩略图悬停效果
2020/12/09 HTML / CSS
Myprotein俄罗斯官网:欧洲第一运动营养品牌
2019/05/05 全球购物
澳大利亚有机化妆品网上商店:The Well Store
2020/02/20 全球购物
经济信息管理专业大学生求职信
2013/09/27 职场文书
优秀的计算机专业求职信范文
2013/12/27 职场文书
求职简历自我评价范例
2014/03/12 职场文书
2014年内部审计工作总结
2014/12/09 职场文书
安全承诺书格式范本
2015/04/28 职场文书
导游词之新疆尼雅遗址
2019/10/16 职场文书
python运算符之与用户交互
2022/04/13 Python