| """ | |
| Utility functions | |
| """ | |
| import logging | |
| from PIL import Image | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| def resize_image(image: Image.Image, max_size: int = 2048) -> Image.Image: | |
| """Resize image if it exceeds max_size (keeping aspect ratio).""" | |
| if max(image.size) <= max_size: | |
| return image | |
| ratio = max_size / max(image.size) | |
| new_size = (int(image.width * ratio), int(image.height * ratio)) | |
| return image.resize(new_size, Image.Resampling.LANCZOS) | |
| def log_error(msg: str): | |
| """Log error with traceback.""" | |
| logger.error(msg, exc_info=True) | |