FastAPI Storefront Cropping: OCR-Safe Hero Images Across Responsive Slots
The least complex reliable design is to run OCR and text moderation on the original property photo, reject or redact disallowed text there, and only then derive every banner crop from that approved source. Use one focal region plus explicit slot dimensions to produce variants. Never let a desktop or mobile crop become a second moderation boundary. Short answer: moderate the full-resolution source…
To crop storefront hero images for desktop and mobile slots in a source-first manner, follow these steps:
1. Accept an image identifier, a focal box selected by a person or detector, and the exact pixel dimensions of the target slots in the API request.
2. Run OCR against the uncropped source image.
3. Apply a policy function to classify the extracted text from the OCR results.
4. If the source image fails the policy, do not generate any crop. If it passes, proceed to step 5.
5. The crop math should be run in a callable interface, like a FastAPI callable function, to allow testing and production use of different OCR implementations without leaking model responses.
6. Create candidate boxes based on the target aspect ratio using the focal box and desired slot dimensions.
7. Score the candidate boxes, rewarding coverage of the focal region and penalizing intersected text boxes.
8. Select the best-scoring crop that does not override the moderation result.
9. Record the source hash and policy version along with the final cropped image.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.