From 0c511992157b55d6719c4920b19452db2c199379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 11 Oct 2022 00:29:27 +0000 Subject: [PATCH] random picture --- api/advent22_api/routers/days.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/api/advent22_api/routers/days.py b/api/advent22_api/routers/days.py index 3ba3a45..5ea02bd 100644 --- a/api/advent22_api/routers/days.py +++ b/api/advent22_api/routers/days.py @@ -91,14 +91,21 @@ async def get_file(path: str) -> BytesIO: return buffer -async def load_picture_standard() -> Image.Image: +async def load_picture_standard( + index: int, +) -> Image.Image: """ Bild laden und einen quadratischen Ausschnitt aus der Mitte nehmen """ + print(await list_images("")) + # Bild laden - img_buffer = await get_file("lena2.jpg") + rnd = random.Random(f"{loesungswort}{index}") + dat = rnd.choice(await list_images("")) + + img_buffer = await get_file(dat) img = Image.open(img_buffer) # Größen bestimmen @@ -114,7 +121,7 @@ async def load_picture_standard() -> Image.Image: )) img = img.resize( - size=(400, 400), + size=(500, 500), resample=Image.ANTIALIAS, ) @@ -186,7 +193,7 @@ async def get_picture_for_day( # Position des Buchstaben bestimmen rnd = random.Random(f"{loesungswort}{index}") - xy = tuple(rnd.choices(range(30, 370), k=2)) + xy = tuple(rnd.choices(range(30, 470), k=2)) # betroffenen Bildbereich bestimmen text_box = await get_text_box(