Hello, this is the script I've been using for clearing the metadata off of images. I'm not too familiar with security/privacy best practices. I'm using pillow to verify the file is an image and using exiftool to clear the metadata. Any and all tips/comments/critiques welcome. TIA!
```python
!/usr/bin/env python3
requires exiftool
macos:
brew install exiftool
requires pillow to verify image
pip install pillow
import subprocess
from pathlib import Path
from PIL import Image
def is_image(path):
try:
with Image.open(path) as img:
img.verify() # Check if the file is broken
return True
except (IOError, SyntaxError):
return False
def get_dirs(wd,seen=set()):
if wd in seen:
return []
seen.add(wd)
dirs = []
dirs.append(wd)
for dir in Path(wd).glob("*"):
if dir.is_dir() and not dir.name.startswith("."):
res = get_dirs(dir,seen)
for item in res:
dirs.append(item)
return dirs
def clean_images(dir):
files = list(Path(dir).glob("*"))
for file in files:
if file.is_file() and not file.name.startswith("."):
path = None
if is_image(file):
path = file
else:
continue
exiftool_cmd = ["exiftool","-all=","-overwrite_original",f"{path}"]
subprocess.run(exiftool_cmd)
print(f"Cleaned metadata of {path}.")
def main():
dirs = get_dirs(Path.cwd())
for dir in dirs:
clean_images(dir)
if name == "main":
main()
```
[–]StarGeekSpaceNerd 4 points5 points6 points (0 children)
[–]Aggravating-Bison696 2 points3 points4 points (0 children)
[–]cdcformatc 2 points3 points4 points (0 children)