I'd be glad to help you with that. Here's a Python code that demonstrates how to get EXIF information from a photo using the exifread
library:
Python
import exifread
def get_exif_info(image_path):
"""
Gets EXIF information from a photo.
Args:
image_path: The path to the image file.
Returns:
dict: A dictionary containing the extracted EXIF tags and their values.
"""
with open(image_path, 'rb') as f:
tags = exifread.process_file(f)
exif_info = {}
for tag, value in tags.items():
exif_info[tag] = str(value)
return exif_info
# Example usage:
image_path = "path/to/your/image.jpg"
exif_info = get_exif_info(image_path)
print(exif_info)
Here's a breakdown of the code:
- Import
exifread
library: Theexifread
library is used to read and parse EXIF data from image files. - Define
get_exif_info()
function: This function takes the path to an image file as input and returns a dictionary containing the extracted EXIF tags and their values. - Open image file: The
open()
function opens the image file in binary read mode ('rb'
). - Process EXIF data: The
exifread.process_file()
function processes the image file and extracts the EXIF data. - Create EXIF info dictionary: An empty dictionary is created to store the extracted EXIF tags and their values.
- Iterate through tags: The
for
loop iterates through the extracted tags and their values. - Add to EXIF info dictionary: The tag and its value are added to the
exif_info
dictionary. - Return EXIF info: The function returns the
exif_info
dictionary containing the extracted EXIF information. - Example usage: The code demonstrates how to call the
get_exif_info()
function with the path to an image file and print the extracted EXIF information.
This code provides a clear and concise way to extract EXIF information from images in Python. You can customize it further to extract specific EXIF tags or perform additional processing on the extracted data.
0 件のコメント:
コメントを投稿