Last active
September 15, 2025 05:14
-
-
Save kairat-beep/3bc7f73a7bee6e6c26998aedaa4d7e7d to your computer and use it in GitHub Desktop.
Remove EXIF data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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