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

作者:疯狂一夏 时间:2022-07-16 12:29:38 

本文实例讲述了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,图片,exif
0
投稿

猜你喜欢

  • python的pip安装以及使用教程

    2022-12-05 11:04:37
  • 20个常用Python运维库和模块

    2023-05-11 21:44:13
  • python定向爬取淘宝商品价格

    2023-10-03 23:33:12
  • Oracle的默认用户密码

    2012-07-11 15:29:22
  • MySQL数据库生产环境的维护工作总结的经验

    2011-12-01 10:20:52
  • 为博客增加社会化分享按钮代码

    2010-01-31 16:52:00
  • Python爬取当网书籍数据并数据可视化展示

    2023-11-20 11:31:14
  • 图片变形扭曲特效js脚本

    2008-11-20 12:57:00
  • 停止事件冒泡和阻止浏览器默认行为的脚本

    2008-09-09 22:09:00
  • JavaScript中的函数声明和函数表达式区别浅析

    2023-08-05 23:22:36
  • PHP file_get_contents设置超时处理方法

    2023-10-18 05:56:46
  • 什么是gzip,人肉gzip?

    2008-11-20 13:01:00
  • pytorch 权重weight 与 梯度grad 可视化操作

    2021-02-15 22:42:20
  • 如何在小空间放置大图片

    2009-08-04 13:04:00
  • 如何用css制作有趣的按钮

    2008-03-17 13:54:00
  • 纯CSS下拉菜单代码

    2008-09-10 12:35:00
  • 段正淳的css笔记(3)标题右侧“更多”的实现

    2007-11-01 21:55:00
  • JS实现长图上下滚动效果

    2023-07-22 10:28:26
  • MYSQL教程:保证安全的备份MYSQL数据库的方法

    2010-03-03 17:12:00
  • Django model序列化为json的方法示例

    2022-08-25 01:39:03
  • asp之家 网络编程 m.aspxhome.com