optimization: image size
This commit is contained in:
parent
daa959bd14
commit
0db0e92b13
1 changed files with 11 additions and 1 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue