From 0db0e92b132f4d1d24771e9de929ca8309f20bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 16 Nov 2023 14:55:02 +0100 Subject: [PATCH] optimization: image size --- api/ovdashboard_api/routers/v1/image.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/api/ovdashboard_api/routers/v1/image.py b/api/ovdashboard_api/routers/v1/image.py index e05f9d8..bbb6484 100644 --- a/api/ovdashboard_api/routers/v1/image.py +++ b/api/ovdashboard_api/routers/v1/image.py @@ -63,13 +63,23 @@ async def find_images_by_prefix( response_class=StreamingResponse, ) async def get_image_by_prefix( + cfg: Config = Depends(get_config), remote_path: str = Depends(RP_IMAGE), name: str = Depends(LM_IMAGE.getter.func), ) -> StreamingResponse: - cfg = await get_config() img = Image.open(BytesIO(await WebDAV.read_bytes(f"{remote_path}/{name}"))) img_buffer = BytesIO() + + width, height = img.size + target_height = cfg.image.height + target_width = int(width * target_height / height) + + img = img.resize( + size=(target_width, target_height), + resample=Image.LANCZOS, + ) + img.save(img_buffer, **cfg.image.save_params) img_buffer.seek(0)