File size: 616 Bytes
c37e95b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
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)