diff --git a/api/advent22_api/config.py b/api/advent22_api/config.py index b697547..c4948d6 100644 --- a/api/advent22_api/config.py +++ b/api/advent22_api/config.py @@ -12,6 +12,7 @@ class User(BaseModel): class Puzzle(BaseModel): background: str + font: str solution: str diff --git a/api/advent22_api/routers/_misc.py b/api/advent22_api/routers/_misc.py index ffd64e2..bab4db7 100644 --- a/api/advent22_api/routers/_misc.py +++ b/api/advent22_api/routers/_misc.py @@ -84,8 +84,9 @@ async def load_image( async def get_auto_image( index: int, - letter: str = Depends(get_letter), - images: list[str] = Depends(list_images_auto), + letter: str, + images: list[str], + cfg: Config, ) -> AdventImage: """ Erstelle automatisch generiertes Bild @@ -95,14 +96,14 @@ async def get_auto_image( image = await load_image(images[index]) rnd = await Random.get(index) - lena_ttf = await dav_get_file("fonts/Lena.ttf") - lena_ttf.seek(0) + font = await dav_get_file(f"files/{cfg.puzzle.font}") + font.seek(0) # Buchstabe verstecken await image.hide_text( xy=tuple(rnd.choices(range(30, 470), k=2)), text=letter, - font=ImageFont.truetype(lena_ttf, 50), + font=ImageFont.truetype(font, 50), ) return image @@ -112,6 +113,7 @@ async def get_image( index: int, letter: str = Depends(get_letter), images: list[str] = Depends(list_images_auto), + cfg: Config = Depends(get_config), ) -> AdventImage: """ Bild für einen Tag erstellen @@ -123,7 +125,12 @@ async def get_image( except RuntimeError: # Erstelle automatisch generiertes Bild - return await get_auto_image(index=index, letter=letter, images=images) + return await get_auto_image( + index=index, + letter=letter, + images=images, + cfg=cfg, + ) async def api_return_image(