How do you distinguish a missing EXIF tag from an explicit value?

getexif provides a mapping-like object for querying numeric EXIF tags and checking their presence.

Pixel experiment and interpretation

A new image has no camera-model tag. Set tag 272 and read it back. Absence only describes the file and cannot identify the capture device.

from PIL import Image

im=Image.new('L',(1,1))
ex=im.getexif()
before=ex.get(272)
ex[272]='DemoCam'
(before,ex.get(272))

Result (None, 'DemoCam')

中文

如何检查图片是否带有指定 EXIF 标签而不猜测缺失值?

getexif 提供类似映射的 EXIF 对象,可按数值标签查询并检测缺失。

像素实验与适用边界

新建图像没有相机型号,写入标签 272 后才可查询到。缺少标签只说明这份文件没提供它,不能据此推断设备。

from PIL import Image

im=Image.new('L',(1,1))
ex=im.getexif()
before=ex.get(272)
ex[272]='DemoCam'
(before,ex.get(272))

结果 (None, 'DemoCam')

References / 参考来源

Keep reading / 继续阅读