我正在尝试收集图像元数据,但发现此错误

2024-06-11 08:39:33 发布

您现在位置:Python中文网/ 问答频道 /正文

from PIL import Image
from PIL.ExifTags import TAGS

# path to the image or video
imagename=input("Enter image path:")

# read the image data using PIL
image=Image.open(imagename)

# extract EXIF data
exifdata=image.getexif()

# in exifdata , all fields are id's not a human readable form
#  iterate over all EXIF data fields

# print(exifdata)
for tag_id in exifdata:
    # get tag name, instead of human unreadavle tag id
    tag=TAGS.get(tag_id,tag_id)
    data=exifdata.get(tag_id)
    # decode bytes
    if isinstance(data,bytes):
        data=data.decode()
        print(f"{tag:25}:{data}")

回溯(最近一次呼叫最后一次): 文件“image_metadata.py”,第23行,在 data=data.decode() UnicodeDecodeError:“utf-8”编解码器无法解码位置1中的字节0xea:无效的连续字节

error image


Tags: thepathfromimageimportiddataget