2023-01-29 21:23:01 +00:00
|
|
|
from logging import getLogger
|
2023-02-05 13:53:26 +00:00
|
|
|
|
2023-01-29 21:23:01 +00:00
|
|
|
from PIL import Image
|
|
|
|
|
2023-02-05 13:53:26 +00:00
|
|
|
from ..params import ImageParams, Size, StageParams
|
2023-02-26 05:49:39 +00:00
|
|
|
from ..server import ServerContext
|
2023-02-26 20:15:30 +00:00
|
|
|
from ..worker import WorkerContext
|
2023-01-29 21:23:01 +00:00
|
|
|
|
|
|
|
logger = getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def reduce_thumbnail(
|
2023-02-26 05:49:39 +00:00
|
|
|
_job: WorkerContext,
|
2023-02-05 13:53:26 +00:00
|
|
|
_server: ServerContext,
|
2023-01-29 21:23:01 +00:00
|
|
|
_stage: StageParams,
|
|
|
|
_params: ImageParams,
|
2023-02-18 22:35:57 +00:00
|
|
|
source: Image.Image,
|
2023-01-29 21:23:01 +00:00
|
|
|
*,
|
|
|
|
size: Size,
|
2023-02-19 04:11:44 +00:00
|
|
|
stage_source: Image.Image,
|
2023-01-29 21:23:01 +00:00
|
|
|
**kwargs,
|
|
|
|
) -> Image.Image:
|
2023-02-19 04:11:44 +00:00
|
|
|
source = stage_source or source
|
2023-02-18 22:35:57 +00:00
|
|
|
image = source.copy()
|
2023-02-18 11:44:43 +00:00
|
|
|
|
|
|
|
# TODO: should use a call to valid_image
|
2023-02-06 23:13:37 +00:00
|
|
|
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)
|
2023-01-29 21:23:01 +00:00
|
|
|
return image
|