Hacker News new | ask | show | jobs
by Spivak 1276 days ago
And honestly that's already amazingly valuable and I've been using it constantly for weeks because it narrows your search space through the documentation to the head of a pin.

Hey I need to process the EXIF data for an image; let's Google "pillow exif" and see what we get.

https://pillow.readthedocs.io/en/stable/reference/ExifTags.h...

Uhh, okay. Kinda? Maybe? This doesn't actually tell me how to actually get that data from a real image.

> Write a python program using pillow to print all the EXIF data for an image in a human readable way

    from PIL import Image
    from PIL.ExifTags import TAGS 

    # Create an Image object 
    img = Image.open('image.jpg') 

    # Get EXIF data
    exif_data = img._getexif() 
 
    # Iterate over all EXIF data fields
    for tag_id in exif_data: 
 
        # Get the tag name, instead of human unreadable tag id
        tag = TAGS.get(tag_id, tag_id) 
 
        data = exif_data.get(tag_id) 
 
        # Decode bytes 
        if isinstance(data, bytes): 
            data = data.decode() 
 
        print(f"{tag:25}: {data}")
Is it correct, sorta, close though. But it tells me I should look for a method on the image object called getexif -- hey it exists, nice! And that's what TAGS is for! Makes way more sense.