Arachnida/Anaconda.py

45 lines
1.3 KiB
Python

import os
import argparse
from PIL import Image
from PIL.ExifTags import TAGS
def get_exif_data(filepath):
"""
Extract and print Exif data from an image file.
"""
try:
image = Image.open(filepath)
exif_data = image._getexif()
if not exif_data:
print(f"No Exif data found in {filepath}")
return {}
exif = {}
for tag_id, value in exif_data.items():
tag = TAGS.get(tag_id, tag_id)
exif[tag] = value
return exif
except Exception as e:
print(f"Error reading Exif data from {filepath}: {e}")
return {}
def main():
parser = argparse.ArgumentParser(description="Program to display Metadata of Images")
parser.add_argument('images', nargs='+', help='Paths to one or more image files')
args = parser.parse_args()
for image_path in args.images:
if not os.path.isfile(image_path):
print(f"File {image_path} does not exist or is not a file.")
continue
exif_data = get_exif_data(image_path)
if exif_data:
print(f"\033[93mExif data for {image_path}:\033[0m")
for tag, value in exif_data.items():
print(f" {tag}: {value}")
else:
print(f"No Exif data found for {image_path}")
if __name__ == "__main__":
main()