avy23/passport-photo-processor
0
PassportPro AI - Image Processor
This is the image processing backend for PassportPro AI, deployed on Hugging Face Spaces.
Features
- ✅ Background removal using rembg
- ✅ Automatic face detection and centering
- ✅ Smart cropping for passport photo standards (413x531px)
- ✅ Image enhancement (contrast, sharpness, brightness)
- ✅ Custom background color support
API Usage
Endpoint: POST /process
Parameters:
image(file): The photo to process (JPEG or PNG)bgColor(string, optional): Background color in hex format (default: #FFFFFF)
Example Request (cURL):
curl -X POST https://YOUR_USERNAME-passport-photo-processor.hf.space/process \
-F "image=@photo.jpg" \
-F "bgColor=#FFFFFF"Example Response:
{
"success": true,
"outputImage": "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
"originalFilename": "photo.jpg",
"processedSize": 125847,
"message": "Photo processed successfully"
}Local Testing
# Install dependencies
pip install -r requirements.txt
pip install fastapi uvicorn python-multipart
# Run the server
python app.pyVisit http://localhost:7860/docs for interactive API documentation.
Deployment on Hugging Face Spaces
- Create a new Space with Docker SDK
- Upload these files:
app.pypassport_process.pyrequirements.txtDockerfileREADME_HF.md(rename to README.md)
- Space will automatically build and deploy
Performance
- Processing Time: 3-8 seconds per image (depends on image size)
- Max Image Size: Recommended < 5MB for faster processing
- Concurrent Requests: Handled sequentially to avoid memory issues
Tech Stack
- FastAPI: Web framework
- rembg: Background removal (uses U2-Net model)
- OpenCV: Face detection
- Pillow: Image manipulation
- Uvicorn: ASGI server
License
MIT License
