python用来获得图片exif信息的库实例分析

yipeiwu_com5年前Python基础

本文实例讲述了python用来获得图片exif信息的库用法。分享给大家供大家参考。具体分析如下:

exif-py是一个纯python实现的获取图片元数据的python库,官方下载地址:
http://exif-py.svn.sourceforge.net/viewvc/exif-py/source/EXIF.py?revision=19&view=markup

下面的代码演示的是调用方法。

复制代码 代码如下:
# library test/debug function (dump given files)
if __name__ == '__main__':
    import sys
    import getopt
    # parse command line options/arguments
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hqsdt:v", ["help", "quick", "strict", "debug", "stop-tag="])
    except getopt.GetoptError:
        usage(2)
    if args == []:
        usage(2)
    detailed = True
    stop_tag = 'UNDEF'
    debug = False
    strict = False
    for o, a in opts:
        if o in ("-h", "--help"):
            usage(0)
        if o in ("-q", "--quick"):
            detailed = False
        if o in ("-t", "--stop-tag"):
            stop_tag = a
        if o in ("-s", "--strict"):
            strict = True
        if o in ("-d", "--debug"):
            debug = True
    # output info for each file
    for filename in args:
        try:
            file=open(filename, 'rb')
        except:
            print "'%s' is unreadable\n"%filename
            continue
        print filename + ':'
        # get the tags
        data = process_file(file, stop_tag=stop_tag, details=detailed, strict=strict, debug=debug)
        if not data:
            print 'No EXIF information found'
            continue
        x=data.keys()
        x.sort()
        for i in x:
            if i in ('JPEGThumbnail', 'TIFFThumbnail'):
                continue
            try:
                print '   %s (%s): %s' % \
                      (i, FIELD_TYPES[data[i].field_type][2], data[i].printable)
            except:
                print 'error', i, '"', data[i], '"'
        if 'JPEGThumbnail' in data:
            print 'File has JPEG thumbnail'
        print

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python with用法:自动关闭文件进程

实际上,Python 提供了 with 语句来管理资源关闭。比如可以把打开的文件放在 with 语句中,这样 with 语句就会帮我们自动关闭文件。 with 语句的语法格式如下:...

Python 模拟员工信息数据库操作的实例

Python 模拟员工信息数据库操作的实例

1.功能简介 此程序模拟员工信息数据库操作,按照语法输入指令即能实现员工信息的增、删、改、查功能。 2.实现方法 • 架构: 本程序采用python语言编写,关键在于指令的解...

matplotlib作图添加表格实例代码

matplotlib作图添加表格实例代码

本文所示代码主要是通过Python+matplotlib实现作图,并且在图中添加表格的功能,具体如下。 代码 import matplotlib.pyplot as plt impo...

通过PYTHON来实现图像分割详解

程序思路: 此次程序主要是利用PIL(Python Image Libraty)这库,来进行图片的处理。 PIL是一个功能非常强大的python图像处理标准库,但由于PIL只支持pyth...

Python使用Pandas库实现MySQL数据库的读写

Python使用Pandas库实现MySQL数据库的读写

本次分享将介绍如何在Python中使用Pandas库实现MySQL数据库的读写。首先我们需要了解点ORM方面的知识 ORM技术 对象关系映射技术,即ORM(Object-Relatio...