python读取图像的exif信息
python 读取图像的exif信息
前几天用PYQT做了一个工具,打开图片发现和原图像有一个转动的变化,后来发现是exif头的信息没有读取,当用open(“name.jpg”, ‘rb’) 以二进制流的形式打开图像,我们如何得到图像的exif信息呢?
import exifread
pip install exifread
导入exifread库,
f = open(filename, 'rb') tags = exifread.process_file(f)
如果你选择的图片有exif信息的话,打印一下tags会是一个字典类型,例如:
{
"Image ImageDescription": (0x010E) ASCII= @ 18,
"Image Make": (0x010F) ASCII=SONY @ 2266,
"Image Model": (0x0110) ASCII=ILCE-6000 @ 2272,
"Image Orientation": (0x0112) Short=Rotated 180 @ 54,
"Image Software": (0x0131) ASCII=ILCE-6000 v3.20 @ 2282,
"Image DateTime": (0x0132) ASCII=2015:01:13 04:27:23 @ 2298,
"Image YCbCrPositioning": (0x0213) Short=Co-sited @ 90,
"Image ExifOffset": (0x8769) Long=2318 @ 102,
"Image SensitivityType": (0x8830) Short=Recommended Exposure Index @ 114,
"Image RecommendedExposureIndex": (0x8832) Long=400 @ 126,
"Image XPTitle": (0x9C9B) Byte=[0, 0] @ 138,
"Image XPSubject": (0x9C9F) Byte=[32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, ... ] @ 42146,
"Image LensSpecification": (0xA432) Ratio=[16, 50, 7/2<