问题:python的Exif操作库

我正在寻找适用于python的良好exif(可交换图像文件格式)操作库。与处理速度相比,我更喜欢灵活性(例如,检索提供商专有标签的能力)。你有什么建议?

I’m looking for good exif (Exchangeable image file format) manipulation library for python. I prefer flexibility (e.g., ability to retrieve providers’ proprietary tags) than processing speed. What would you suggest?


回答 0

您可能要签出exif-py

从tiff和jpeg文件提取EXIF数据的Python库。非常易于使用-$ ./EXIF.py image.jpg

Python Imaging Library(PIL)

Python Imaging Library(PIL)为您的Python解释器添加了图像处理功能。该库支持多种文件格式,并提供强大的图像处理和图形功能。

还有一个恰当命名的pyexif:http ://pyexif.sourceforge.net/

pyexif python库和工具旨在从包含它的Jpeg和Tiff文件中提取EXIF信息。此信息通常包含在使用数字成像设备(例如,数码相机,数字胶片扫描仪等)创建的图像中。

但是,似乎pyexif尚未更新。他们建议,如果他们的技巧不正确,不能签出EXIF-py,那么您可能应该首先尝试一下,因为他们的sourceforge页面最近似乎有一些活动,尽管数量不多。最后,使用PIL您可以执行以下操作:

from PIL import Image
from PIL.ExifTags import TAGS

def get_exif(fn):
    ret = {}
    i = Image.open(fn)
    info = i._getexif()
    for tag, value in info.items():
        decoded = TAGS.get(tag, tag)
        ret[decoded] = value
    return ret

免责声明
实际上我不知道哪个是最好的,这就是我与Google共同努力的结果。:)

You might want to check out exif-py:

Python library to extract EXIF data from tiff and jpeg files. Very easy to use – $ ./EXIF.py image.jpg

or the Python Imaging Library (PIL):

The Python Imaging Library (PIL) adds image processing capabilities to your Python interpreter. This library supports many file formats, and provides powerful image processing and graphics capabilities.

There’s also the aptly named pyexif: http://pyexif.sourceforge.net/

The pyexif python library and tools aims at extracting EXIF information from Jpeg and Tiff files which include it. This information is typically included in images created using digital imaging devices such as digital cameras, digital film scanners, etc.

However, it looks like pyexif hasn’t been updated in quite while. They recommend if theirs isn’t doing the trick to check out EXIF-py, so you should probably try that one first, as their sourceforge page seems to have some activity there lately, though not much. Finally, using PIL you could do this:

from PIL import Image
from PIL.ExifTags import TAGS

def get_exif(fn):
    ret = {}
    i = Image.open(fn)
    info = i._getexif()
    for tag, value in info.items():
        decoded = TAGS.get(tag, tag)
        ret[decoded] = value
    return ret

Disclaimer:
I actually have no idea which is best, this is just what I was able to piece together with Google. :)


回答 1

我最近一直在使用pyexiv2,它似乎非常适合我的需求。也许它也适合您。

I’ve been using pyexiv2 myself recently, and it seems to fit my needs quite nicely. Perhaps it might suit yours as well.


回答 2

基于Exiv2的解决方案

Exiv2(exiv2:http://exiv2.org/ )是一个成熟的开源C ++库,支持将元数据读取和写入多种图像类型(JPEG,PNG,TIFF和许多原始格式),并了解标准(Xmp,IPTC)和Exif)和非标准元数据(“ Makernotes”),并且可以在多种平台(Windows,Linux和Mac)上运行。

Python与exiv2的绑定是:

  • gexiv2(多语言绑定,但适用于python 2.6 / 2.7 / 3.X):https ://wiki.gnome.org/gexiv2
  • pyexiv2(不再受支持,但可与python 2.6 / 2.7一起使用):http ://tilloy.net/dev/pyexiv2/

pyexiv2的一个优点是有一个可用于python 2.7的Windows构建。针对gexiv2的Windows构建请求位于此处:https ://bugzilla.gnome.org/show_bug.cgi?id = 712441

exiv2和绑定都是开源的(GPL)。

Exiv2 Based solutions

Exiv2 (exiv2: http://exiv2.org/) is a mature, open-source C++ library that supports reading and writing metadata to many image types (JPEG, PNG, TIFF and many raw formats), understands standard (Xmp, IPTC and Exif) and non-standard metadata (“Makernotes”), and runs on multiple platforms (Windows, Linux, and, with some work, Mac).

Python bindings to exiv2 are:

One advantage of pyexiv2 is that there is a windows build available for python 2.7. A windows build request for gexiv2 is here: https://bugzilla.gnome.org/show_bug.cgi?id=712441

exiv2 and the bindings are all open source (GPL).


回答 3

本文介绍了一个Python模块,用于使用纯Python编写EXIF元数据(而不仅仅是读取它们)。显然,PIL,pyexif或EXIF-py都不支持编写EXIF。pyexiv2似乎是尖端的,并且是特定于平台的。

This article describes a Python module for writing EXIF metadata (and not just reading them) using pure Python. Apparently, none of PIL, pyexif, nor EXIF-py support writing EXIF. pyexiv2 appears to be bleeding-edge and platform-specific.


回答 4

使用PIL :)

import os,sys
from PIL import Image
from PIL.ExifTags import TAGS

if __name__ == '__main__':
    for (k,v) in Image.open(sys.argv[1])._getexif().iteritems():
        print '%s = %s' % (TAGS.get(k), v)
    os.system('pause')

Use PIL :)

import os,sys
from PIL import Image
from PIL.ExifTags import TAGS

if __name__ == '__main__':
    for (k,v) in Image.open(sys.argv[1])._getexif().iteritems():
        print '%s = %s' % (TAGS.get(k), v)
    os.system('pause')

回答 5

http://redmine.yorba.org/projects/gexiv2/wiki(成为https://wiki.gnome.org/Projects/gexiv2)上的页面现在读取:

这对于Python 2或3同样适用,这使GExiv2成为仅支持Python 2的pyexiv2的理想替代品。

因此,GExiv2现在支持Python2和Python3。

好消息。

The page at http://redmine.yorba.org/projects/gexiv2/wiki (became https://wiki.gnome.org/Projects/gexiv2) reads now:

This will work equally well with either Python 2 or 3, which makes GExiv2 an excellent replacement for pyexiv2, which only supports Python 2.

So, both Python2 and Python3 are now supported by GExiv2.

Good news.


回答 6

您还可以在http://www.emilas.com/jpeg/上查看Gheorghe Milas的jpeg.py库,该库是“用于解析,读取和写入JPEG EXIF,IPTC和COM元数据的python库”。

缺点是他似乎通过DynDNS将其域托管在动态IP上,因此它并不总是可用。

You might also look at Gheorghe Milas’ jpeg.py library at http://www.emilas.com/jpeg/, which is “A python library to parse, read and write JPEG EXIF, IPTC and COM metadata.”

A drawback is that he appears to be hosting his domain on a dynamic IP via DynDNS, so it’s not always available.


回答 7

我用上面的Paolo代码以某种方式获得_getexif的attributeError。我正在使用Python 2.6.6和PIL 1.1.7。_getexif现在过时了吗?

这是一个对我有用的小修改。

from PIL import Image
from PIL.ExifTags import TAGS

def get_exif(fn):
    ret = {}
    i = Image.open(fn)
#    info = i._getexif()
    info = i.tag.tags
    for tag, value in info.items():
        decoded = TAGS.get(tag, tag)
        ret[decoded] = value
    return ret

somehow i get an attributeError for _getexif with Paolo’s code above.. I am using Python 2.6.6 and PIL 1.1.7. Is _getexif obsolete now??

Here’s a small modification that worked for me.

from PIL import Image
from PIL.ExifTags import TAGS

def get_exif(fn):
    ret = {}
    i = Image.open(fn)
#    info = i._getexif()
    info = i.tag.tags
    for tag, value in info.items():
        decoded = TAGS.get(tag, tag)
        ret[decoded] = value
    return ret

回答 8

我开始根据PIL中的代码编写自己的小型库。 在这里检查

I started to write my own small library which is based on the code in PIL. check it here.


回答 9

我一直在http://www.sno.phy.queensu.ca/~phil/exiftool/周围使用我自己的包装器 -原因是它非常完整,开发人员非常活跃。而且,不支持几乎所有图像格式对于该项目来说绝对是必不可少的。

当然,缺点是它不是python,因此您需要像我一样使用子进程调用。

I have been using my own wrappers around http://www.sno.phy.queensu.ca/~phil/exiftool/ — the reason is that it is very complete, the dev is very active. And not being able to support almost all image formats is a absolute showstopper for the project it is needed for

The drawback of course is that it isn’t python, so you would need to use subprocess calls, as I do.


回答 10

上有PIL和EXIF.py一些用法示例ASPN

There are some examples of PIL and EXIF.py usage on ASPN


回答 11

在Python 2.6中,模块的位置不同。用这个:

import Image    
from ExifTags import TAGS

In Python 2.6 the place of module is different. Use this:

import Image    
from ExifTags import TAGS

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。