Face Blur

Face Blur is a small offline tool that blurs faces in a photo. You can use it from the command line, or in a local web page where you choose which faces to blur and draw extra areas. The photo never leaves your computer, and the output has no metadata. It is part of the Useful Tools collection.

What it does

  • Auto mode. One command finds every face in a photo and blurs it: face-blur auto photo.jpg photo-blurred.jpg. It prints how many faces it blurred.
  • Manual mode in a local web page. The page shows a box on each face it found. Click a box to turn the blur on or off for that face. Switch to Draw and drag a rectangle to blur any other area, for example a name tag or a face the detector missed. Then Preview and Download.
  • Three methods. gaussian (a soft blur, the default), pixelate (blocks) and solid (one flat colour). The strength goes from 1 to 10.
  • The same strength on every face. The blur size grows with the size of each face, so a small face in the background and a large face in front look equally hidden.
  • Shapes. Faces get an ellipse with a soft edge by default (or a rectangle). The tool adds 15% around each face box, so the hairline and chin are also covered.
  • Formats. JPEG, PNG and WebP in and out.

Nothing leaves your computer

  • The model is in the package. The face detector is YuNet, a small ONNX model (about 230 KB, MIT licence) from the OpenCV model zoo. It is in the repository with a pinned SHA-256 checksum, and a test checks it. Nothing is downloaded when the tool runs.
  • The web page is local. The server listens on 127.0.0.1 only. If you choose another host with --host, the tool prints a warning. The page has no CDN and no external scripts.
  • No temp files. The server keeps no state. The browser sends the image again with each request, and the server answers from memory. There is nothing to clean up.
  • No metadata in the output. Photos often carry EXIF data: camera, date, sometimes the GPS position. The tool first turns the image the right way up from its EXIF orientation, then writes the output without any metadata.

Install and run

You need Python 3.12 or newer and uv. Get the code from the repository, go into the tool-face-blur folder and run uv sync. Then:

  • uv run face-blur auto IN OUT blurs all faces. The output format comes from the extension of OUT (.jpg, .png or .webp). Options: --method, --strength, --shape, --padding, --min-score, --quality.
  • uv run face-blur detect IN prints the face boxes as JSON.
  • uv run face-blur serve starts the web page on port 8765 and opens it in your browser.

If the tool finds no face, it still writes the output and prints a warning.

Choose the right method

A soft blur at a low strength hides less than it seems. Part of the detail is only weakened, not removed, and a person who knows the face can still recognise it. For a photo where privacy really matters:

  • use --method solid: a flat colour leaves no face detail at all, or
  • use a high strength (the blur radius at strength 10 is 40% of the face size).

Remember that hair, clothes and the background stay visible. Blur them too with Draw mode if they can identify the person.

Limits

  • The detector can miss very small faces or faces seen from the side. Lower --min-score (default 0.6), or draw the area by hand in the web page.
  • The web page accepts files up to 25 MB and 40 megapixels.
  • It works on single images. It does not process video.

How it was built

  • Stack. Python 3.12 with uv, OpenCV for detection and blur (cv2.FaceDetectorYN), Pillow for reading and writing images, and Flask for the local server. The web page is plain HTML, JavaScript and a canvas, with no build step.
  • Why YuNet. It is much more accurate than the old Haar cascades, especially for small and turned faces, and it runs in plain OpenCV. MediaPipe was the other option, but it is a heavier install and had weak wheel support for Python 3.12 on Apple Silicon.
  • One pipeline. The command line, the web page and the API all call the same detect-and-blur code. A code review found that padding was applied differently in the web page than in the command line, so a region now records whether it came from the detector or from the user. Now all three give the same result.
  • Tests. 72 pytest tests, plus ruff and mypy in strict mode. The test photo is the public-domain Apollo 11 portrait of Neil Armstrong (NASA), with a rotated copy to test EXIF orientation.
  • Built with a Claude Code agent pipeline: one implementation agent, then a code review, then fixes.

Links