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

30 lines
687 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
2023-02-19 02:28:21 +00:00
from ..server import JobContext, 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,
*,
size: Size,
stage_source: Image.Image,
**kwargs,
) -> Image.Image:
source = stage_source or source
image = source.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