Python读取图片EXIF信息类库介绍和使用实例
作者:junjie 发布时间:2023-05-27 00:49:47
首先要介绍的是 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应用中,常常会遇见点击某个链接会弹出一个新的窗口,或者是相互关联的web应用 ,这样要去操作新窗口中的元素,这时就需要主机切换到新窗
- BEGIN -- 声明变量 DECLARE v_addtime_begin varchar(13); DECLARE v_addtime_e
- 本文总结了一些简单基本的输出格式化形式,下面话不多说了,来看看详细的介绍吧。一、打印字符串>>> print "
- 本文实例讲述了python和mysql交互操作。分享给大家供大家参考,具体如下:python要和mysql交互,我们利用pymysql这个库
- 详解微信小程序中的页面代码中的模板的封装 最近在进行微信小程序中的页面开发,其实在c++或者说是js中都
- 本文实例讲述了Go语言字典(map)用法。分享给大家供大家参考,具体如下:字典是一种内置的数据结构,用来保存 键值对 的 无序集合。(1)字
- 简介这两天更新完Xcode8之后发现Xcode对图标的要求又有了变化,之前用的一个小应用“IconKit”还没赶上节奏,已经不能满足Xcod
- 本文实例讲述了JavaScript让Textarea支持tab按键的方法。分享给大家供大家参考。具体实现方法如下:HTMLTextAreaE
- [sql] -- ===================【创建存储过程】===================== USE [Message
- 开发工具**Python版本:**3.6.4相关模块:pyecharts模块;以及一些Python自带的模块。环境搭建安装Python并添加
- 可用性研究表明,当响应时间超过一秒钟时,用户便能够有所察觉。虽然在反馈系统中,当用户需要等待时,更好的解决方案的是应该采用确定性的进度条。但
- 今天给大家分享的主题是用百度的接口实现图片的文字识别。1.环境和配置要求整体是用Python实现,所需要使用的第三方库包括aip、PIL、k
- mysql-5.6.14-win32为免安装解压缩版,安装版(http://dev.mysql.com/downloads/installe
- 一,进程的理论基础一个应用程序,归根结底是一堆代码,是静态的,而进程才是执行中的程序,在一个程序运行的时候会有多个进程并发执行。进程和线程的
- 我们将要来学习python的重要概念迭代和迭代器,通过简单实用的例子如列表迭代器和xrange。可迭代一个对象,物理或者虚拟存储的序列。li
- 代码的作用在于保证在上端缓存服务失效(一般来说概率比较低)时,形成倒瓶颈,从而能够保护数据库,数据库宕了,才是大问题(比如影响其他应用)。假
- Sql Server 中一个非常强大的日期格式化函数: 获得当前系统时间,GETDATE(): 2008年01月08日 星期二 14:59
- APScheduler是一个Python定时任务框架,使用起来十分方便。提供了基于日期、固定时间间隔以及crontab类型的任务,并且可以持
- 在执行python 代码的时候,有时候需要传递外面的参数进行处理这个该怎么实现呢?需要一个模块from sys import argv当然也
- 在Thread和Process中,应当优选Process,因为Process更稳定,而且,Process可以分布到多台机器上,而Thread