Open derrianx opened 1 year ago
try this
import exifread import os import csv
directory = '/path/to/directory'
with open('metadata.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
# Write the header row
writer.writerow(['Filename', 'ISO', 'Aperture', 'Shutter Speed', 'Focal Length'])
# Iterate through all the files in the directory
for filename in os.listdir(directory):
# Only process JPEG files
if filename.endswith('.jpg'):
# Open the image file
with open(os.path.join(directory, filename), 'rb') as f:
# Extract EXIF metadata
tags = exifread.process_file(f)
# Write the metadata for the current image to the CSV file
writer.writerow([filename, tags["EXIF ISOSpeedRatings"], tags["EXIF FNumber"], tags["EXIF ExposureTime"], tags["EXIF FocalLength"]])
infoDict = {} #Creating the dict to get the metadata tags exifToolPath = 'D:/ExifTool/exifTool.exe' #for Windows user have to specify the Exif tool exe path for metadata extraction.
"""exifToolPath = exiftool""" imgPath = 'D:/Images/12.jpg'
''' use Exif tool to get the metadata ''' process = subprocess.Popen([exifToolPath,imgPath],stdout=subprocess.PIPE, stderr=subprocess.STDOUT,universal_newlines=True) ''' get the tags in dict ''' for tag in process.stdout: line = tag.strip().split(':') infoDict[line[0].strip()] = line[-1].strip()
for k,v in infoDict.items(): print(k,':', v)
https://www.thepythoncode.com/article/extracting-image-metadata-in-python