Dev.to Security ๐Ÿ” Cybersecurity ๐Ÿ‘ 0 ๐Ÿ“– 6 min read

Every photo you share is a database about your life. I built a Python tool to read it, score it, and scrub it

Right now, the last photo you posted probably knows more about you than the caption does. A JPEG is not just pixels. It usually carries the exact GPS position where it was taken, the make and model of the device that too

Right now, the last photo you posted probably knows more about you than the caption does. A JPEG is not just pixels. It usually carries the exact GPS position where it was taken, the make and model of the device that took it, the precise second of capture, and sometimes the camera's serial number or the owner's name. Social platforms strip some of this on upload, but anything you share directly, over chat, email, a forum attachment, or a cloud link, keeps all of it.

I wanted one small, dependency-light tool that answers three questions about any image: what does it leak, how bad is the leak, and can I get a copy that is safe to share? The result is Image_info, a Python CLI and library whose only hard dependency is Pillow. This post walks through how it works, with everything below actually executed while writing this article, not copied from the README.

The three commands that matter

The tool ships 15 subcommands (info, exif, gps, privacy, strip, report, duplicates, and more). I cloned the repo, installed Pillow 12.3.0 and pytest on Python 3.10.12, and started with the test suite:

$ python3 -m pytest -q
91 passed in 6.54s

Then I generated the built-in sample set (imageinfo demo), which creates a realistic photo stamped with EXIF: a fictional "PixelWorks PW-7 Pro" camera, a capture timestamp, and the GPS position of Petra, Jordan. From here on, every output block is a real run against that file.

Reading the file: EXIF and GPS forensics

imageinfo exif dumps everything the file carries:

  Make                         PixelWorks
  Model                        PW-7 Pro
  Software                     PW-Camera 3.2.1
  DateTime                     2025:09:30 17:42:10
  GPS.GPSLatitude              (30.0, 19.0, 42.6)
  GPS.GPSLongitude             (35.0, 26.0, 39.8004)
  GPS.GPSAltitude              910.0
  Exif.FocalLength             4.3
  Exif.ISOSpeedRatings         200

imageinfo gps converts the DMS values to decimal and reverse geocodes them through Nominatim (OpenStreetMap), no API key needed:

  Latitude     30.328500
  Longitude    35.444389
  Altitude     910 m
  Address      "Royal tombs" footpath, ูˆุงุฏูŠ ู…ูˆุณู‰, Petra Sub-District, ู…ุนุงู†, ุงู„ุฃุฑุฏู†

The reverse geocoding needs network access, but the map the tool generates (--map map.html) is a single self-contained HTML file using Leaflet with OpenStreetMap tiles, so sharing or archiving the result does not phone home to a maps provider. That was a deliberate design change: the project originally used the Google Maps approach and moved away from it to drop the API key requirement.

Scoring the leak

Knowing a file has GPS data is one thing. Knowing how much it matters is another. imageinfo privacy runs every finding through a weighted scoring model and explains each one in plain language:

Privacy risk: Critical (78/100)
  Location    Exact capture location: 30.32850, 35.44439, altitude 910 m
              [high GPS.latitude/longitude]
  Device      Device fingerprint: PixelWorks PW-7 Pro
              [medium EXIF.Make/Model]
  Timeline    Capture timestamp: 2025:09:30 17:42:10
              [medium EXIF.DateTimeOriginal]
  Software    Editing/capture software: PW-Camera 3.2.1
              [low EXIF.Software]
  Filesystem  File modified at 2026-11-27 16:34:50
              [low filesystem.mtime]

The model is simple on purpose, and readable in image_info/privacy.py. Exact GPS coordinates are the single worst leak at 45 points. A device fingerprint and a capture timestamp add 12 each. Serial numbers and owner names (BodySerialNumber, LensSerialNumber, OwnerName, Artist) sit in the identity category at 8 to 10 points. Scores cap at 100 and map to Low (under 20), Medium, High, and Critical (75 and up). The demo photo lands at 78: GPS 45 + device 12 + timestamp 12 + software 5 + filesystem 4.

The weights are judgment calls, not science, and the code says so by keeping them in one obvious table you can tune. The point is not a universal metric, it is a fast triage: is this file fine to post, or should I scrub it first?

Scrubbing: why rebuilding pixels beats deleting tags

The naive way to strip metadata is to delete the EXIF segment. That misses things: XMP packets, PNG text chunks, embedded thumbnails, and comments all survive a naive EXIF delete. strip_metadata takes the stronger route. It opens the image, bakes the orientation tag into the pixels with ImageOps.exif_transpose so the photo still displays upright, then rebuilds a brand-new image from raw pixel values:

def _clean_pixels(image: Image.Image) -> Image.Image:
    """Rebuild an image from raw pixel values only - no metadata attached."""
    clean = Image.new(image.mode, image.size)
    clean.putdata(list(image.getdata()))
    return clean

A fresh Image carries no metadata at all, so there is nothing left to miss. Animated GIFs and WebPs keep every frame, duration, and loop count, and the function refuses to write over the source file, because re-encoding pixels in place would destroy your only original. Here is the real run:

$ imageinfo strip petra_sunset.jpg -o clean.jpg
Stripped metadata: 17 tag(s) removed, GPS removed
  320,708 B -> 259,580 B (+61,128 B)  ->  clean.jpg

$ imageinfo exif clean.jpg
This file carries no EXIF metadata.

$ imageinfo privacy clean.jpg
Privacy risk: Low (4/100)

The parenthetical is the byte saving, printed with a leading plus by the CLI.

From Critical 78 to Low 4. The only remaining finding is the filesystem modification time, which no image tool can change from inside the file.

Finding duplicates with perceptual hashing

The last piece is a duplicate finder that works even when files have different names, sizes, and bytes. It uses dHash: resample to 9x8 greyscale, record for each pixel whether it is brighter than its left neighbour, and you get a 64-bit fingerprint where visually similar images differ by only a few bits.

def dhash(image: Image.Image, hash_size: int = 8) -> int:
    grey = image.convert("L").resize(
        (hash_size + 1, hash_size), Image.Resampling.LANCZOS
    )
    pixels = list(grey.getdata())
    bits = 0
    for row in range(hash_size):
        row_start = row * (hash_size + 1)
        for col in range(hash_size):
            left = pixels[row_start + col]
            right = pixels[row_start + col + 1]
            bits = (bits << 1) | (1 if left > right else 0)
    return bits

Grouping is union-find over the unique hashes: two images join a group when their hashes differ by at most 8 bits and their mean brightness differs by at most 16/255. That brightness tie-breaker exists for a specific reason: solid-colour images all hash to zero, so without it, every flat image in your library would merge into one giant false-positive group.

The proof it works: after stripping, clean.jpg is a completely different file from petra_sunset.jpg at the byte level (different size, different SHA-256), yet the scanner groups it with the original and the exact byte copy:

$ imageinfo duplicates image_info_demo
Group 1
  clean.jpg               (253.5 KB, 1600x1000, dHash 06070b575715...)
  petra_sunset (copy).jpg (313.2 KB, 1600x1000, dHash 06070b575716...)
  petra_sunset.jpg        (313.2 KB, 1600x1000, dHash 06070b575716...)

1 group(s), 3 redundant file(s), 641,416 bytes recoverable

Three files, one dHash bit apart, correctly grouped despite one of them being a full re-encode.

Reports, charts, and one dependency

Everything else follows the same philosophy. imageinfo report produces a single self-contained HTML file (about 139 KB for the demo photo) with the thumbnail, EXIF tables, risk badge, and charts embedded as base64, so it works offline and can be emailed or archived as one file. The histogram and palette charts are drawn with Pillow itself, which is why the whole project avoids matplotlib and stays at one runtime dependency.

What I verified, and what I did not

Everything shown above was executed on Python 3.10.12 with Pillow 12.3.0 while writing this post: the 91-test suite, the EXIF/GPS reads, the live reverse geocode, the privacy score before and after stripping, and the duplicate grouping. Two honest caveats: the supported-extension list includes HEIC, but actually opening HEIC depends on your Pillow build (typically via pillow-heif), which I did not exercise; and reverse geocoding needs network access to Nominatim, though every other feature, including the map file it produces, works offline.

If you want to audit your own library before your next upload, the repo is here: github.com/ALSRKAL/Image_info, MIT licensed. pip install ., then imageinfo privacy on anything you are about to share.

๐Ÿ“ฐ Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.