Spaces:
Configuration error
Configuration error
Download app/image_processor.py from Samidha21/emosaic-backend: direct link, hf CLI and curl.
- Browser
- Download file 723 Bytes
-
https://huggingface.co/spaces/Samidha21/emosaic-backend/resolve/main/app/image_processor.py
- Command line
-
hf download hf://spaces/Samidha21/emosaic-backend/app/image_processor.py
-
curl -L -o image_processor.py https://huggingface.co/spaces/Samidha21/emosaic-backend/resolve/main/app/image_processor.py
723 Bytes
| import numpy as np | |
| from PIL import Image | |
| def load_image(file): | |
| image = Image.open(file) | |
| # Convert everything to RGB | |
| image = image.convert("RGB") | |
| return image | |
| def resize_image(image, resolution): | |
| width, height = image.size | |
| # Clamp resolution | |
| resolution = max(40, min(300, resolution)) | |
| aspect_ratio = width / height | |
| if width >= height: | |
| new_width = resolution | |
| new_height = int(resolution / aspect_ratio) | |
| else: | |
| new_height = resolution | |
| new_width = int(resolution * aspect_ratio) | |
| resized = image.resize( | |
| (new_width, new_height), | |
| Image.LANCZOS | |
| ) | |
| return resized | |
| def image_to_array(image): | |
| return np.array(image) |