Skip to content

Instantly share code, notes, and snippets.

@kairat-beep
Last active September 15, 2025 05:14
Show Gist options
  • Select an option

  • Save kairat-beep/3bc7f73a7bee6e6c26998aedaa4d7e7d to your computer and use it in GitHub Desktop.

Select an option

Save kairat-beep/3bc7f73a7bee6e6c26998aedaa4d7e7d to your computer and use it in GitHub Desktop.
Remove EXIF data
from PIL import Image
import os
for root, _, files in os.walk("."):
for f in files:
if f.lower().endswith(('.jpg', '.jpeg', '.png')):
path = os.path.join(root, f)
try:
with Image.open(path) as img:
exif_bytes = img.info.get("exif")
# If exif_bytes is present, write a copy without it
if exif_bytes:
img.save(path, exif=b"")
print(f"Stripped EXIF from: {path}")
else:
# Just re-save without specifying exif
img.save(path)
print(f"No EXIF to strip: {path}")
except Exception as e:
print(f"Failed on {path}: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment