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.0.tar.gz (5.2 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.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for passport_cropper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5aff3790a3740637ebeed45a1a9d9fed5aabbe5a4b6fb831609cb1664c3484cb
MD5 560cfc0e9897f27b13d682a02584f959
BLAKE2b-256 32f5e0eac487ec793883a0a6b45f13473240cbcd6518bc9f274d75f7270a106d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for passport_cropper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73d6bdacc3566d70cde745d03795564849d9e67e5d5c211f0f7ea232a836f7f2
MD5 f97023bc9feac39a6c89a543b902bef8
BLAKE2b-256 fd94d6a1bcf1849186fc4437f8131da07ec7fadfae1563633a86d5b289801685

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