Spaces:
Runtime error
Runtime error
Download utils/crop.py from AdityaAKUMAR/OCR_API: direct link, hf CLI and curl.
- Browser
- Download file 498 Bytes
-
https://huggingface.co/spaces/AdityaAKUMAR/OCR_API/resolve/main/utils/crop.py
- Command line
-
hf download hf://spaces/AdityaAKUMAR/OCR_API/utils/crop.py
-
curl -L -o crop.py https://huggingface.co/spaces/AdityaAKUMAR/OCR_API/resolve/main/utils/crop.py
498 Bytes
| from PIL import Image | |
| import io | |
| import base64 | |
| def crop_face(image_bytes, bbox): | |
| image = Image.open(io.BytesIO(image_bytes)) | |
| width, height = image.size | |
| ymin, xmin, ymax, xmax = bbox | |
| x1 = int(xmin / 1000 * width) | |
| y1 = int(ymin / 1000 * height) | |
| x2 = int(xmax / 1000 * width) | |
| y2 = int(ymax / 1000 * height) | |
| face = image.crop((x1, y1, x2, y2)) | |
| buffer = io.BytesIO() | |
| face.save(buffer, format="JPEG") | |
| return base64.b64encode(buffer.getvalue()).decode() |