我试着用Pillow从图片中提取Exif元数据。
当我在GIMP或XnView上导入我的图片时,软件返回给我Exif元数据 。
然而,当我像这样运行我的Python脚本时。
from PIL import Image
from PIL.ExifTags import TAGS
def get_exif():
i = Image.open('./Datatest_img/DAFANCH96_023MIC07633_L.jpg')
info = i._getexif()
return {TAGS.get(tag): value for tag, value in info.items()}
print(get_exif())
脚本返回给我一个错误,如果图像不包含EXIF元数据。
Traceback (most recent call last):
File "test_exif.py", line 17, in <module>
print(get_exif())
File "test_exif.py", line 15, in get_exif
return {TAGS.get(tag): value for tag, value in info.items()}
AttributeError: 'NoneType' object has no attribute 'items'
我也试着在我的脚本中打印.info,代码返回.info,然后我在命令行中运行exiftool,终端打印::EXIF元数据。
{None: (200, 200)}
我在命令行中运行exiftool,终端打印.info。
$ exiftool DAFANCH96_023MIC07633_L.jpg
ExifTool Version Number : 11.99
File Name : DAFANCH96_023MIC07633_L.jpg
Directory : .
File Size : 791 kB
File Modification Date/Time : 2020:05:27 22:46:56+02:00
File Access Date/Time : 2020:05:28 10:54:31+02:00
File Inode Change Date/Time : 2020:05:27 22:46:57+02:00
File Permissions : rw-r--r--
File Type : JPEG
File Type Extension : jpg
MIME Type : image/jpeg
JFIF Version : 1.01
Resolution Unit : inches
X Resolution : 200
Y Resolution : 200
Image Width : 4096
Image Height : 2944
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 1
Image Size : 4096x2944
Megapixels : 12.1
任何人都有一个想法吗?有谁知道这是怎么回事? 谢谢。