EXIF python PIL return 空字典

EXIF python PIL return empty dictionary

我不明白为什么 _getexif() returns 是一个空字典。我知道图像包含 ImageMagic 显示的 EXIF 数据:

>> identify -verbose image.jpg

Properties:
    date:create: 2015-01-12T16:20:26-05:00
    date:modify: 2013-07-01T14:05:08-04:00
    exif:ColorSpace: 1
    ...

exif:Model: PC800 PROFESSIONAL
    exif:ResolutionUnit: 2
    exif:SceneCaptureType: 0
    exif:WhiteBalance: 1
    exif:XResolution: 72/1
    exif:YCbCrPositioning: 2
    exif:YResolution: 72/1
    jpeg:colorspace: 2
    jpeg:sampling-factor: 2x1,1x1,1x1
    signature: e63fcbacdfd031e611b83befaa4a9c8ef6235894da10784a692f90832205ec60
  Profiles:
    Profile-exif: 931 bytes

现在尝试用 python2

读取 EXIF
img = Image.open('image.jpg')
>>> img
<PIL.JpegImagePlugin.JpegImageFile image.jpg mode=RGB size=2048x1536 at 0x7FEDF2E8A518>
exif = img._getexif()
>>> exif

returns没什么...

我也尝试过使用 pyexiv2,结果相同:

>>> import pyexiv2
>>> metadata = pyexiv2.ImageMetadata(img)
>>> metadata.read()
>>> metadata.exif_keys
[]

为什么我无法将这些 exif 数据读入 python? Python Arch Linux.

上的 2.7.8(默认,2014 年 9 月 24 日,18:26:21)

作为使用 _getexif() 的替代方法,我们可以使用 subprocess.chck_output 到 运行 identify 并将输出解析为字典:

from subprocess import check_output

c = check_output("identify -verbose img.jpg".split())
d = {}
print(c)
for line in c.splitlines()[:-1]:
    spl = line.split(":",1)
    k, v = spl
    d[k.lstrip()] = v.strip()
print(d)

{'Blue': '', 'Border color': 'srgb(223,223,223)', 'Compression': 'JPEG', 'Elapsed time': '0:01.000', 'Artifacts': '', 'Overall': '', 'blue primary': '(0.15,0.06)', 'Dispose': 'Undefined', 'jpeg': 'sampling-factor: 2x2,1x1,1x1', 'red primary': '(0.64,0.33)', 'Interlace': 'JPEG', 'Compose': 'Over', 'Tainted': 'False', 'Filesize': '3.9KB', 'Pixels per second': '0B', 'Units': 'Undefined', 'Chromaticity': '', 'Number pixels': '7.5K', 'Type': 'TrueColor', 'Red': '', 'Channel depth': '', 'blue': '8-bit', 'Background color': 'white', 'Transparent color': 'black', 'verbose': 'true', 'min': '0 (0)', 'Resolution': '72x72', 'Image statistics': '', 'filename': 'img.jpg', 'green primary': '(0.3,0.6)', 'Print size': '1.38889x1.04167', 'Channel statistics': '', 'Class': 'DirectClass', 'red': '8-bit', 'Matte color': 'grey74', 'Page geometry': '100x75+0+0', 'skewness': '-0.284137', 'Geometry': '100x75+0+0', 'max': '255 (1)', 'Colorspace': 'sRGB', 'Depth': '8-bit', 'Green': '', 'date': 'modify: 2015-01-13T19:18:06+00:00', 'User time': '0.000u', 'Rendering intent': 'Perceptual', 'kurtosis': '0.369947', 'Gamma': '0.454545', 'Orientation': 'Undefined', 'Endianess': 'Undefined', 'Image': 'img.jpg', 'Format': 'JPEG (Joint Photographic Experts Group JFIF format)', 'white point': '(0.3127,0.329)', 'Properties': '', 'green': '8-bit', 'Iterations': '0', 'signature': '620e0541b826edb6dc5a2420beaaf697fdf6682ba50f915b8ab767fafbb3b7d2', 'standard deviation': '46.9874 (0.184264)', 'Quality': '85', 'mean': '133.602 (0.52393)'}

如果您不想使用空值的键,请在添加 key/value

之前使用 if v