By: Manoj in Python Tutorials on 2023年03月17日 [フレーム]
Here is the Python program to get location metadata from an image using the exifread library in Python.
import exifread
def get_location(image_path):
with open(image_path, 'rb') as f:
tags = exifread.process_file(f)
lat_ref = tags.get('GPS GPSLatitudeRef')
lat = tags.get('GPS GPSLatitude')
lon_ref = tags.get('GPS GPSLongitudeRef')
lon = tags.get('GPS GPSLongitude')
if lat and lat_ref and lon and lon_ref:
lat_val = convert_to_degrees(lat)
if lat_ref.values[0] == 'S':
lat_val = -lat_val
lon_val = convert_to_degrees(lon)
if lon_ref.values[0] == 'W':
lon_val = -lon_val
return (lat_val, lon_val)
else:
return None
def convert_to_degrees(value):
d = float(value.values[0].num) / float(value.values[0].den)
m = float(value.values[1].num) / float(value.values[1].den)
s = float(value.values[2].num) / float(value.values[2].den)
return d + (m / 60.0) + (s / 3600.0)
# Example usage:
location = get_location('image.jpg')
if location:
print('Latitude:', location[0])
print('Longitude:', location[1])
else:
print('No location data found in image metadata.')
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in Python )
Retrieve Twitter posts and comments using Python
Python program to get location meta data from an image
How to install Jupyter in Ubuntu and make it accessible through Apache Reverse Proxy
Installing gedit for python programming in Windows
Latest Articles (in Python)
Python program to get location meta data from an image
Retrieve Twitter posts and comments using Python
How to install Jupyter in Ubuntu and make it accessible through Apache Reverse Proxy
Python Basics - Setting up your Python Development Environment
Schwartzian Transform in python
Multidimensional list (array) in python
Perl's chomp() equivalent for removing trailing newlines from strings in python
Python program to get location meta data from an image
Retrieve Twitter posts and comments using Python
How to install Jupyter in Ubuntu and make it accessible through Apache Reverse Proxy
Python Basics - Setting up your Python Development Environment
Schwartzian Transform in python
Multidimensional list (array) in python
Perl's chomp() equivalent for removing trailing newlines from strings in python
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate