doc-crop
Detect documents in photos, apply perspective correction, and compress to target size.
Prerequisites
brew install MikeChongCan/tap/doc-crop
This taps and installs in one command. Requires macOS 13+ (uses Vision framework).
Usage
doc-crop <input> <output> [options]
Options
| Flag | Default | Description |
|---|---|---|
--max-size <KB> |
200 |
Max output file size |
--quality <0-100> |
75 |
Initial compression quality |
--no-perspective |
off | Skip perspective correction (crop only) |
Examples
# Receipt photo → clean WebP ≤200KB
doc-crop receipt.jpg receipt.webp
# Tighter compression
doc-crop photo.jpg out.webp --quality 60 --max-size 100
# Crop only, no straightening
doc-crop scan.png output.jpg --no-perspective
Output formats
Determined by output file extension: .webp, .jpg/.jpeg, .png.
WebP and JPEG support iterative quality reduction to meet --max-size. PNG does not.
How it works
- Vision framework detects document region (falls back to rectangle detection)
CIPerspectiveCorrectionstraightens the detected quadrilateral (3% padding)- Encodes to target format, iteratively reducing quality until under
--max-size - If no document detected, falls back to 5% margin crop