Arachnida/Scorpion.py

71 lines
2.1 KiB
Python

import os
import argparse
from PIL import Image
from PIL.ExifTags import TAGS
def get_file_metadata(filepath):
"""
Extract and print metadata from an image file.
"""
try:
image = Image.open(filepath)
metadata = {
'Filename': os.path.basename(filepath),
'Format': image.format,
'Mode': image.mode,
'Size': image.size,
'Info': image.info
}
return metadata
except Exception as e:
print(f"Error reading metadata from {filepath}: {e}")
return {}
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}")
metadata = get_file_metadata(image_path)
if metadata:
print(f"\033[92mMetadata for {image_path}:\033[0m")
for key, value in metadata.items():
print(f" {key}: {value}")
else:
print(f"No Exif data found for {image_path}")
if __name__ == "__main__":
main()