from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS

def get_exif_data(image_path):
    # 打开图片文件
    image = Image.open(image_path)
    exif_data = image._getexif()  # 获取 EXIF 数据
    if not exif_data:
        return None  # 如果没有 EXIF 数据，返回 None

    # 转换 EXIF 标签为人类可读格式
    readable_exif = {}
    for tag_id, value in exif_data.items():
        tag_name = TAGS.get(tag_id, tag_id)
        readable_exif[tag_name] = value
    return readable_exif

# 使用示例
image_path = "2.jpg"
exif = get_exif_data(image_path)
if exif:
    for key, value in exif.items():
        print(f"{key}: {value}")
else:
    print("No EXIF data found.")
