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)