Learn Data Analysis
  • Home
  • Python
    • Pandas
    • Matplotlib
    • PyQt5
    • Google Tasks API
    • Google Sheets API
    • Google Gmail API
    • Google Photos API
    • Google YouTube API
    • Google Translation API
    • Google Vision API
    • Simple-Salesforce
    • win32com
    • xlwings
  • Excel
    • VBA
  • Office
    • Access
    • Outlook
    • PowerPoint
    • Word
  • Trailhead
  • About Me
Select Page

How to extract image metadata | Python Tutorial

Jan 8, 2020 | Python | 0 comments

In this lesson, we are going to learn how to use Python to extract image file metadata.


Buy Me a Coffee? Your support is much appreciated!
PayPal Me: https://www.paypal.me/jiejenn/5
Venmo: @Jie-Jenn





Source Code:

import os
from PIL import Image
from PIL.ExifTags import TAGS
import pandas as pd

img_file = 'DSCF4025.jpg'

image = Image.open(img_file)

for tag, value in image._getexif().items():
    if tag in TAGS:
        print(TAGS[tag])
        exif[TAGS[tag]] = value


# list comprehension
exif = {TAGS[k]: v for k, v in image._getexif().items() if k in TAGS}

if 'GPSInfo' in exif:
    # to convert to Geodetic Coordinate
    geo_coodinate = '{0} {1} {2:.2f} {3}, {4} {5} {6:.2f} {7}'.format(
        exif['GPSInfo'][2][0][0],
        exif['GPSInfo'][2][1][0],
        exif['GPSInfo'][2][2][0] / exif['GPSInfo'][2][2][1],
        exif['GPSInfo'][1],
        exif['GPSInfo'][4][0][0],
        exif['GPSInfo'][4][1][0],
        exif['GPSInfo'][4][2][0] / exif['GPSInfo'][2][2][1],
        exif['GPSInfo'][3]
        )

    print(geo_coodinate)

Submit a Comment Cancel reply

Your email address will not be published. Required fields are marked *

Search Post

Subscribe My YouTube Channel

Other Posts

  • Access (3)
  • Automate Google Tasks API with Python (4)
  • Automation Scripts (10)
  • Data Analytics (8)
  • Data Visualization (10)
  • Excel (42)
  • Excel General (11)
  • Google API (General) (2)
  • Google Calendar API (2)
  • Google Docs (1)
  • Google Drive API (2)
  • Google Gmail API (2)
  • Google Maps APIs (1)
  • Google Photos API (6)
  • Google Sheets API (14)
  • Google Translation API (2)
  • Google Video Intelligence API (1)
  • Google Vision API (15)
  • Google YouTube API (7)
  • LeetCode (1)
  • Matplotlib (10)
  • Microsoft SQL Server (3)
  • Office Automation (12)
  • Other Tutorials (1)
  • Outlook (7)
  • Pandas (6)
  • PowerPoint (3)
  • PyQt5 (104)
  • Python (226)
  • Resources (1)
  • Salesforce Trailhead (33)
  • Selenium (1)
  • Simple-Salesforce (4)
  • Uncategorized (10)
  • VBA (30)
  • Web Scraping (2)
  • win32com (2)
  • Word (5)
  • XlsxWriter (4)
  • xlwings (5)
Copyright © LearnDataAnalysis.org