Skip to main content

Passport Cropper 🪪📷

Automatically crop passport-style photos from scanned forms or images using face detection and image orientation correction.. Ensures correct orientation, centers the face, and optionally compresses the image to stay within a specified file size (e.g., under 100KB). Ideal for scanned documents, selfies, or batch passport photo generation.

This tool detects a face in a scanned form (even if rotated), intelligently crops the surrounding area to form a clean passport-size photo, and optionally compresses it to stay under a specified file size.


✨ Features

  • 🧠 Face detection using OpenCV
  • 📐 Intelligent orientation correction (handles rotated/scanned forms)
  • ✂️ Crops a clean passport-style image around the face
  • 💾 Automatically resizes/compresses image under a max file size (optional)
  • 🛠️ Easy to use as a library or script
  • 🐍 Open Source and available on PyPI

📦 Installation

pip install passport-cropper

🧑‍💻 Usage

from passport_cropper import crop_passport_photo

# Crop and save image from scanned form
cropped = crop_passport_photo(
    image_path="admission_form.jpg",
    output_path="passport_photo.jpg",
    max_size_kb=100   # Optional - limit output image size
)
# No face detected if cropped is None.

if cropped:
  print("Image processed successfully!")

You can also run it directly as a script (CLI version coming soon):

python -m passport_cropper path/to/form.jpg

🖼️ Input / Output Example

Input: Scanned or mobile photo of an admission form (rotated, tilted, or normal)

Output: Clean, upright, passport-style photo of the face cropped and optionally compressed.


📁 Project Structure

passport_cropper/
├── passport_cropper/
│   ├── __init__.py
│   └── cropper.py
├── examples/
├── README.md
├── LICENSE
├── setup.py
├── requirements.txt

⚙️ Parameters

Parameter Type Description
image_path str Path to the input image
output_path str Path to save the cropped passport image
max_size_kb int (Optional) Max size (in KB) for output image

🔧 Requirements

  • Python 3.7+
  • OpenCV

Install via:

pip install -r requirements.txt

🛡️ License

This project is licensed under the MIT License. See the LICENSE file for details.


🙌 Contributing

Pull requests are welcome! If you find a bug or want a new feature, feel free to open an issue or submit a PR.



✍️ Author

Developed with ❤️ by Abhay Braja

Let me know if you'd like me to insert your actual name and GitHub username, or generate a minimal working CLI wrapper too.

Metadata

Release files for passport-cropper 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for passport-cropper 0.1.1
File Size Uploaded
passport_cropper-0.1.1.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for passport-cropper 0.1.1
File Interpreter ABI Platform
passport_cropper-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / passport_cropper-0.1.1.tar.gz

Download URL passport_cropper-0.1.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4ef0436ea758c8adf5a9f39b9b41eb577ed4defff00caedea92ce3d173f2c940
BLAKE2b-256 checksum
How to use checksums
e741af89b43a37f28c248f0a02b9c14cfd84eb3d12d054ececf489be4c3ecfeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / passport_cropper-0.1.1-py3-none-any.whl

Download URL passport_cropper-0.1.1-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23205fd84c1af078d166119d2d1f90f2e3d44396c917edd7d832597b78a6204e
BLAKE2b-256 checksum
How to use checksums
230a77ca581b7dca8bee63b5f0b7b1d0e516aa3950f5239c8a93fe3d06a20a17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page