Every photo you take with your smartphone contains invisible data embedded directly in the image. GPS coordinates accurate to a few meters, device model, operating system version, date and time of capture. The technical term: EXIF metadata.
Anyone who shares a photo without removing this data also shares their location, device and the time of capture. This applies to messengers, email, Nostr, and private servers. Platforms with automatic EXIF stripping are the exception, not the rule.
This script cleans images in the Downloads folder on the device before they are sent anywhere.
1. What EXIF Data Contains
Typical fields in EXIF metadata of a camera photo:
- GPS coordinates (latitude, longitude, sometimes altitude)
- Device manufacturer and model (e.g. Google Pixel 9 Pro)
- Operating system version
- Date and time of capture
- Camera settings (aperture, exposure time, ISO)
Android screenshots generally do not contain GPS coordinates. AI-generated images from ComfyUI or Stable Diffusion carry no EXIF data at all. The main risk is with photos taken directly by the camera app.
2. Setup: Python and Termux
If not done yet, set up access to device storage first:
termux-setup-storage
Confirm the dialog ("Allow"). Then install Python and the Pillow library:
pkg update && pkg upgrade
pkg install python
pip install pillow
Create a scripts folder:
mkdir -p ~/Skripte
3. The Script: exif-cleaner.py
The script reads images from the Downloads folder, creates pixel-accurate copies without embedded metadata, and saves them to a bereinigt/ subfolder. The original files remain untouched.
Create the file:
nano ~/Skripte/exif-cleaner.py
Paste the content:
#!/usr/bin/env python3
"""
exif-cleaner.py - Removes all metadata (EXIF) from images (Termux version)
Cleaned images are saved in a 'bereinigt/' subfolder.
"""
import os
import sys
from pathlib import Path
from PIL import Image
SUPPORTED = {'.jpg', '.jpeg', '.png', '.webp', '.bmp', '.tiff', '.tif'}
def clean_image(src_path, dst_path):
with Image.open(src_path) as img:
data = img.tobytes()
clean = Image.frombytes(img.mode, img.size, data)
clean.save(dst_path)
def main():
print("Alien EXIF-Cleaner (Termux)")
print("-" * 40)
base = Path.home() / "storage" / "downloads"
folder = input(f"Subfolder in {base}/ (empty = entire Downloads folder): ").strip()
src_dir = base / folder if folder else base
if not src_dir.exists() or not src_dir.is_dir():
print(f"Folder not found: {src_dir}")
sys.exit(1)
images = [f for f in src_dir.iterdir() if f.suffix.lower() in SUPPORTED]
if not images:
print(f"No images found in: {src_dir}")
sys.exit(1)
dst_dir = src_dir / "bereinigt"
dst_dir.mkdir(exist_ok=True)
print(f"\nSource: {src_dir}")
print(f"Target: {dst_dir}")
print(f"Images: {len(images)} found\n")
ok = 0
errors = 0
for img_path in sorted(images):
dst = dst_dir / img_path.name
try:
clean_image(img_path, dst)
print(f" ok {img_path.name}")
ok += 1
except Exception as e:
print(f" ERR {img_path.name} - Error: {e}")
errors += 1
print("\n" + "-" * 40)
print(f"{ok} images cleaned -> {dst_dir}")
if errors:
print(f"{errors} errors")
if __name__ == "__main__":
main()
(Save in nano: CTRL+O, Enter, then CTRL+X)
4. Running the Script
python ~/Skripte/exif-cleaner.py
The script asks for a subfolder within ~/storage/downloads/. Press Enter to process all images in the entire Downloads folder.
Cleaned copies are saved to:
~/storage/downloads/bereinigt/
Supported formats: JPG, PNG, WebP, BMP, TIFF.
5. How the Cleaning Works
The approach is deliberately straightforward: Pillow reads the raw pixel data (img.tobytes()) and builds a new image object from it (Image.frombytes()). This new object contains no EXIF fields, no ICC profiles, no embedded thumbnails. Only the pixel data itself.
To verify that cleaning worked, use exiftool on a desktop:
exiftool cleaned-photo.jpg
Expected output: few or no fields, no GPS.
No invisible data. No location. No device. That is the goal.
More in This Series
Encrypt and decrypt folders directly on your smartphone:
The Mobile Bunker: Encryption on GrapheneOS (Termux Edition)
Unzip all archives in Downloads with a single command:
Unzip Archives with Termux
Tools for Real Owners (Ads/Affiliate)
Tools I use myself, for Bitcoin self-custody and digital sovereignty:
-
GrapheneOS Handbook:
My ebook "GrapheneOS: Android in the Age of Surveillance" — the complete guide to everything only touched on here.
https://alien-investor.org/buecher -
Buy Bitcoin in Europe: 21bitcoin
Bitcoin-only app from Europe, ideal for DCA. Use code ALIENINVESTOR for a permanent 0.2 percentage point fee reduction.
https://alien-investor.org/21bitcoin -
₿ Bitcoin Self-Custody:
Hardware wallet instead of exchange account. I use the BitBox.
https://alien-investor.org/bitbox -
Privacy and Mail: Proton
Email, VPN and cloud without Big Tech dependency.
https://alien-investor.org/proton
Disclosure: Some links are affiliate links. Using them supports my work at no extra cost to you.