detect-exif — EXIF Metadata Detection and Removal Tool

Image credit: DALL·E 3

The Privacy Problem

I recently discovered a privacy problem while updating this website - photos and images containing sensitive metadata. From GPS coordinates showing exactly where a photo was taken to camera serial numbers and timestamps, digital images often carry a surprising amount of personal information! This invisible data creates significant privacy risks when sharing images online, potentially exposing your location history and device information to anyone who downloads your photos.

The Solution

The detect-exif tool is my solution to this issue. I built it after discovering how much data my own photos on this website were exposing (you can read the full story in my blog post). It works both as a pre-commit hook and a standalone command-line tool. While there are many tools that can already remove EXIF data, I found none that would integrate easily with pre-commit.

If you’re curious about what kind of data might be hiding in your own images, try running detect-exif on your photo collection (please do not use --remove, you might regret it)! Alternatively, for more information, you can look at file information in Mac/Windows to see a whole suite of EXIF metadata.

Key Features

  • Detects various types of sensitive EXIF data in JPG, PNG, and WebP images
  • Highlights particularly concerning information (like GPS coordinates) with human-readable output
  • Preserves image orientation when removing metadata
  • Works as a pre-commit hook to catch privacy issues before they’re committed
  • Simple installation via pip
  • Minimal dependencies (only requires Python and Pillow)

How it works

The tool scans image files using the Python Pillow library to extract and analyze metadata. When it finds sensitive information, it can either just alert you (perfect for CI/CD pipelines) or automatically sanitize the images (great for batch processing).

Here’s what the output looks like when detect-exif finds sensitive data:

$ detect-exif vacation.jpg
⚠️ SENSITIVE INFORMATION DETECTED:
    • GPS Coordinates: 37.774929, -122.419416
    • Camera: iPhone 14 Pro
    • Timestamp: 2025-03-15 14:32:49

Getting Started

Installation

# Install from PyPI
pip install detect-exif

Usage

# Check images without modifying them
detect-exif img1.jpeg img2.png img3.webp

# Remove metadata while preserving orientation
detect-exif --remove img1.jpg

Pre-commit Integration

Add this to your .pre-commit-config.yaml:

- repo: https://github.com/olipinski/detect-exif
  rev: v0.1.0
  hooks:
    - id: detect-exif
      # args: ["--remove", "--quiet"]

Try detect-exif!

If you find it useful or have ideas for improvements, contributions are welcome on GitHub.

Olaf Lipinski
Olaf Lipinski
Researcher in Artificial Intelligence

Making sure AI actually helps in real-world scenarios.