首先要介绍的是 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)
其他类库请自行研究。
- 上一篇:Web服务器框架 Tornado简介
- 下一篇:Python中的魔法方法深入理解
相关文章
相关视频
- 在Django框架中运行Python应用全攻略
- 在Python的Django框架中创建和使用模版
- python获取元素在数组中索引号的方法
- 浅谈python中截取字符函数strip,lstr...
- Python读取图片EXIF信息类库介绍和使用实例
- Python 简介
- Python 环境搭建
- Python 中文编码
- Python 基础语法
- Python 变量类型
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论
立即提交
专题推荐
- 独孤九贱-php全栈开发教程
全栈 100W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
- 玉女心经-web前端开发教程
入门 50W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
- 天龙八部-实战开发教程
实战 80W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
作者信息
php教程
认证0级讲师
- 最近文章
发布技术文章
- 最新文章
- 热门排行
- python之禅怎么打出来
- python怎么学
- boosting和bootstrap区别
- python库是什么意思
- python卸载后怎么也安装不上
- python安装后怎么不见了
- python怎么卸载模块
- python能做什么?是什么?
- pickle库的使用详解
- Anaconda的新手使用大全
- python爬虫是什么?为什么把python叫做爬虫?
- Python微信库:itchat的用法详解
- 关于python3学习基础知识总结
- python爬虫是什么
- 使用Python可以做什么
- python如何实现可视化热力图
推荐视频教程
视频教程分类
- php视频教程
- html视频教程
- css视频教程
- JS视频教程
- jQuery视频教程
- mysql视频教程
- Linux视频教程
- Python视频教程
- 网站首页
- PHP视频
- PHP实战
PHP中文网:独家原创,永久免费的在线php视频教程,php技术学习阵地!
Copyright 2014-2019 http://www.php.cn/ All Rights Reserved | 皖B2-20150071-9 皖公网安备 34010402701654号 免责申明赞助与捐赠