Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to extract image metadata in Python?

  • Last Updated : 03 Jan, 2021

Prerequisites: PIL

Metadata stands for data about data. In case of images, metadata means details about the image and its production. Some metadata is generated automatically by the capturing device. 

Some details contained by image metadata is as follows:

  • Height
  • Width
  • Date and Time
  • Model etc.

Python has PIL library which makes the task of extracting metadata from an image extremely easy that too by using just a few lines.


  • Import the pillow module.
  • Load the image
  • Get the metadata. The metadata so obtained
  • Convert it into human-readable form

There are many types of metadata but in this we are only focusing on Exif metadata


These metadata, often created by cameras and other capture devices, include technical information about an image and its capture method, such as exposure settings, capture time, GPS location information and camera model.

for this i have used this picture(link for this is below) make sure whatever picture you are using it  should have some metadata of EXIF type and most of the capturing devices have exif data 

NOTE:-please avoid the image shared through whatsapp. Whatsapp strips away all metadata from any image 


Step 1: Importing modules.

Step 2: Load the image and extract the exif data.

Step 3: Convert the exif tag id(denoted by tagid in the code ) into human readable form denoted by tagname in the code and getting its respective value.

Application to extract  Metadata from a image with pillow : below script implements the above approach


from PIL import Image
from PIL.ExifTags import TAGS
# open the image
image ="img.jpg")
# extracting the exif metadata
exifdata = image.getexif()
# looping through all the tags present in exifdata
for tagid in exifdata:
    # getting the tag name instead of tag id
    tagname = TAGS.get(tagid, tagid)
    # passing the tagid to get its respective value
    value = exifdata.get(tagid)
    # printing the final result
    print(f"{tagname:25}: {value}")


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!