Skip to main content

Auto-crop passport photos from scanned documents using face detection.

Project description

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.


🌐 Links


✍️ 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

passport_cropper-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

passport_cropper-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file passport_cropper-0.1.1.tar.gz.

File metadata

  • Download URL: passport_cropper-0.1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for passport_cropper-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4ef0436ea758c8adf5a9f39b9b41eb577ed4defff00caedea92ce3d173f2c940
MD5 ab9ccc43a706483f3c5cbd6fd5a056e5
BLAKE2b-256 e741af89b43a37f28c248f0a02b9c14cfd84eb3d12d054ececf489be4c3ecfeb

See more details on using hashes here.

File details

Details for the file passport_cropper-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for passport_cropper-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23205fd84c1af078d166119d2d1f90f2e3d44396c917edd7d832597b78a6204e
MD5 7ec314880aeec9c7450e2f0d2409c343
BLAKE2b-256 230a77ca581b7dca8bee63b5f0b7b1d0e516aa3950f5239c8a93fe3d06a20a17

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page