/  Blog /
EnglishPython - Delete Metadata

Python - Delete Metadata

Eingetragen: 25.08.2023

Python Script: A small Python script for removing metadata in images. Various image formats are taken into account.

After a run, there is a summary of how much space was saved by removing the metadata.

An existing installation of Python is required. Before running the script, make sure that you have installed the required libraries.

Attention. The files are irrevocably overwritten. If you are not sure, create a backup before.

 pip install Pillow

 import os
from PIL import Image

def remove_metadata(image_path):
image =

Before running the script, make sure that you have installed the required libraries
image_without_metadata =, image.size)

# Save the image without metadata
return True
except Exception as e:
print(f"Error removing metadata from {image_path}: {e}")
return False

def process_folder(folder_path):
total_removed_bytes = 0

for root, _, files in os.walk(folder_path):
for file in files:
if file.lower().endswith(('.jpg', '.png', '.gif', '.svg', '.bmp', '.tiff', '.webp')):
image_path = os.path.join(root, file)
original_size = os.path.getsize(image_path)

if remove_metadata(image_path):
new_size = os.path.getsize(image_path)
removed_bytes = original_size - new_size
total_removed_bytes += removed_bytes
# Optional screen output
print(f"Metadaten von {image_path} entfernt.")

total_removed_mb = total_removed_bytes / (1024 * 1024)
# Optional screen output
print(f"Gesamt entfernte Metadaten: {total_removed_mb:.2f} Megabyte")

if __name__ == "__main__":
folder_path = r"C:\Pictures" # Customize Path



  Rules for posting comments can be found in the F.A.Q.