1
0
Fork 0
onnx-web/api/onnx_web/chain/reduce_thumbnail.py

29 lines
663 B
Python
Raw Normal View History

from logging import getLogger
2023-02-05 13:53:26 +00:00
from PIL import Image
2023-02-05 13:53:26 +00:00
from ..params import ImageParams, Size, StageParams
from ..server.device_pool import JobContext
2023-02-05 13:53:26 +00:00
from ..utils import ServerContext
logger = getLogger(__name__)
def reduce_thumbnail(
2023-02-05 13:53:26 +00:00
_job: JobContext,
_server: ServerContext,
_stage: StageParams,
_params: ImageParams,
source_image: Image.Image,
*,
size: Size,
**kwargs,
) -> Image.Image:
image = source_image.copy()
2023-02-18 11:44:43 +00:00
# TODO: should use a call to valid_image
image = image.thumbnail((size.width, size.height))
2023-02-18 11:44:43 +00:00
2023-02-05 13:53:26 +00:00
logger.info("created thumbnail with dimensions: %sx%s", image.width, image.height)
return image