简体   繁体   中英

I can't get all metadata tags in Python with Pillow

I'm trying to get all metadata tags from an image using the Pillow library but I get only 5 tags here :

ExifOffset          :140
Make                :HUAWEI
Model               :VOG-L29
Software            :Adobe Lightroom 5.0 (Android)
DateTime            :2019:12:10 11:40:30

This is my code :

from PIL import Image
from PIL.ExifTags import TAGS


file = 'IMG_20191210_114027.jpg'
img = Image.open(file)

img_exif = img.getexif()

for tag_id in img_exif:
    tag=TAGS.get(tag_id,tag_id)
    data=img_exif.get(tag_id)
    if isinstance(data,bytes):
        data=data.decode()
    print(f"{tag:20}:{data}")

and this is the pic I was using IMAGE

If we check this WEBSITE we get more tags like:

Make                    HUAWEI
Model                   VOG-L29
Software                Adobe Lightroom 5.0 (Android)
ModifyDate              2019:12:10 11:40:30
ExposureTime            1/6900
FNumber                 1.6
ExposureProgram         Program AE
DateTimeOriginal        2019:12:10 11:40:30
ShutterSpeedValue       1/6900
ApertureValue           1.6
BrightnessValue         0
ExposureCompensation    0
MaxApertureValue        1.6
MeteringMode            Multi-segment
LightSource             Daylight
Flash                   No Flash
FocalLength             5.6 mm
SubSecTime              758
SubSecTimeOriginal      758
FocalLengthIn35mmFormat 55 mm
LensModel               HUAWEI P30 Pro Rear Main Camera

How can I get all tags like on metapicz website? And how can I store each tag in different variable?

from PIL import Image
from PIL.ExifTags import TAGS

imagename = "abc.jpg"
image = Image.open(imagename)

exifdata = image.getexif()

for tag_id in exifdata:
    tag = TAGS.get(tag_id, tag_id)
    data = exifdata.get(tag_id)
    if isinstance(data, bytes):
        data = data.decode()
    print(f"{tag:25}: {data}")

I run those code on Google collab and gave me those result结果图

I ran your code exactly with the latest version of Pillow (Pillow==8.4.0) and got the same incomplete result. Then I downgraded to the version 7.0.0 and it worked!

pip install pillow==7.0.0 --upgrade

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM