cropsize

Crop a scan, straighten it, and print it at exactly the size the real document is.

Runs on your own machine. Nothing you scan gets uploaded.
The cropsize editor with a document detected and measured
The sample scan, found and measured at 104.9 by 147.9 mm. The document is 105 by 148.

The problem

You scanned a passport, an ID card, a certificate. Now you need it on A4, cropped clean, straight, and at exactly the size the real thing is, because the office you are sending it to will reject it otherwise.

Every scanning app crops. Almost none of them get the size right.

What is different

It knows how big things are

A scanner writes the scanned area into a PDF at 1 to 1, so the real size falls straight out of the pixel count. No preset, no guessing, no asking you what the object is.

It finds paper on paper

A passport in a clear sleeve has no brightness step to threshold, so ordinary edge detection grabs the printing instead. Segment Anything 2 finds objects by what they are.

It keeps rounded corners

A crop has to be a rectangle, so the corners pick up whatever sits outside the curve. cropsize traces the real outline and clears those corners to white.

How close does it get

Scancropsize readsOff by
Passport on white126.1 by 177.0 mm1.1 and 1.0 mm
Passport in a plastic sleeve127.2 by 175.4 mm2.2 and 0.6 mm
ID card on a flatbed85.6 by 53.9 mm0.0 and 0.1 mm
Sample document104.9 by 147.9 mm0.1 and 0.1 mm

A passport spread is 125 by 176 mm by international standard, so these are measured against a known answer. The same content scanned at 150, 300, 600 and 1200 dpi measures the same, because a PDF has no dpi of its own and the page geometry is what carries the size.

The finished A4 page with the document at true size
The finished sheet. A4 at 210 by 297 mm, document at its own size, corners cleaned.

Run it

git clone https://github.com/okturan/cropsize.git
cd cropsize
./run.sh

Open localhost:8077 and click Try the sample. That is the whole tour.

For real work add the model, then restart:

./.venv/bin/pip install -r requirements-sam.txt

Weights come from Hugging Face the first time you use them, about 320 MB, and stay on disk after that.

This page is not the app. cropsize runs locally today. A version that runs entirely in the browser is in progress, using the same model exported to ONNX, where the encoder takes 0.74 s and each click takes 36 ms on plain CPU. Until then the link above is the way in.