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命令行传递实例化对象的方法
Nov 02 Python
Python实现网站注册验证码生成类
Jun 08 Python
使用Pyinstaller的最新踩坑实战记录
Nov 08 Python
python通过Windows下远程控制Linux系统
Jun 20 Python
Python人脸识别第三方库face_recognition接口说明文档
May 03 Python
在PyTorch中Tensor的查找和筛选例子
Aug 18 Python
python多线程使用方法实例详解
Dec 30 Python
如何使用python实现模拟鼠标点击
Jan 06 Python
python global和nonlocal用法解析
Feb 03 Python
tensorflow 利用expand_dims和squeeze扩展和压缩tensor维度方式
Feb 07 Python
pytorch之Resize()函数具体使用详解
Feb 27 Python
Python中实现输入一个整数的案例
May 03 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与javascript的两种交互方式
2006/10/09 PHP
php中用文本文件做数据库的实现方法
2008/03/27 PHP
PHP 删除文件与文件夹操作 unlink()与rmdir()这两个函数的使用
2011/07/17 PHP
php excel reader读取excel内容存入数据库实现代码
2012/12/06 PHP
phpmailer简单发送邮件的方法(附phpmailer源码下载)
2016/06/13 PHP
PHP中Cookie的使用详解(简单易懂)
2017/04/28 PHP
php 二维数组快速排序算法的实现代码
2017/10/17 PHP
PHP的RSA加密解密方法以及开发接口使用
2018/02/11 PHP
Laravel5.5 手动分页和自定义分页样式的简单实现
2019/10/15 PHP
javascript当中的代码嗅探扩展原生对象和原型(prototype)
2013/01/11 Javascript
js中数组Array的一些常用方法总结
2013/08/12 Javascript
jQuery中.live()方法的用法深入解析
2013/12/30 Javascript
JS实现超简单的仿QQ折叠菜单效果
2015/09/21 Javascript
js在ie下打开对话窗口的方法小结
2016/10/24 Javascript
javascript表单正则应用
2017/02/04 Javascript
Angular中的$watch、$watchGroup、$watchCollection
2017/06/25 Javascript
使用vue-route 的 beforeEach 实现导航守卫(路由跳转前验证登录)功能
2018/03/22 Javascript
React中的render何时执行过程
2018/04/13 Javascript
200行HTML+JavaScript实现年会抽奖程序
2019/01/22 Javascript
浅谈function(函数)中的动态参数
2017/04/30 Python
浅谈对yield的初步理解
2017/05/29 Python
python 猴子补丁(monkey patch)
2019/06/26 Python
Python+Appium实现自动化测试的使用步骤
2020/03/24 Python
python3获取控制台输入的数据的具体实例
2020/08/16 Python
Django实现简单的分页功能
2021/02/22 Python
英国骑行、跑步、游泳、铁人三项运动装备专卖店:Wiggle
2016/08/23 全球购物
高中微机老师自我鉴定
2014/02/16 职场文书
身边的榜样活动方案
2014/08/20 职场文书
2014年自愿离婚协议书
2014/10/10 职场文书
中秋客户感谢信
2015/01/22 职场文书
劳资员岗位职责
2015/02/13 职场文书
电子商务专业求职信范文
2015/03/19 职场文书
个人求职意向书
2015/05/11 职场文书
网吧员工管理制度
2015/08/05 职场文书
旷工检讨书大全
2015/08/15 职场文书
VS2019连接MySQL数据库的过程及常见问题总结
2021/11/27 MySQL