Config.puzzle.font

This commit is contained in:
Jörn-Michael Miehe 2023-09-04 21:42:58 +00:00
parent 05750d6de2
commit 17b6950491
2 changed files with 14 additions and 6 deletions

View file

@ -12,6 +12,7 @@ class User(BaseModel):
class Puzzle(BaseModel): class Puzzle(BaseModel):
background: str background: str
font: str
solution: str solution: str

View file

@ -84,8 +84,9 @@ async def load_image(
async def get_auto_image( async def get_auto_image(
index: int, index: int,
letter: str = Depends(get_letter), letter: str,
images: list[str] = Depends(list_images_auto), images: list[str],
cfg: Config,
) -> AdventImage: ) -> AdventImage:
""" """
Erstelle automatisch generiertes Bild Erstelle automatisch generiertes Bild
@ -95,14 +96,14 @@ async def get_auto_image(
image = await load_image(images[index]) image = await load_image(images[index])
rnd = await Random.get(index) rnd = await Random.get(index)
lena_ttf = await dav_get_file("fonts/Lena.ttf") font = await dav_get_file(f"files/{cfg.puzzle.font}")
lena_ttf.seek(0) font.seek(0)
# Buchstabe verstecken # Buchstabe verstecken
await image.hide_text( await image.hide_text(
xy=tuple(rnd.choices(range(30, 470), k=2)), xy=tuple(rnd.choices(range(30, 470), k=2)),
text=letter, text=letter,
font=ImageFont.truetype(lena_ttf, 50), font=ImageFont.truetype(font, 50),
) )
return image return image
@ -112,6 +113,7 @@ async def get_image(
index: int, index: int,
letter: str = Depends(get_letter), letter: str = Depends(get_letter),
images: list[str] = Depends(list_images_auto), images: list[str] = Depends(list_images_auto),
cfg: Config = Depends(get_config),
) -> AdventImage: ) -> AdventImage:
""" """
Bild für einen Tag erstellen Bild für einen Tag erstellen
@ -123,7 +125,12 @@ async def get_image(
except RuntimeError: except RuntimeError:
# Erstelle automatisch generiertes Bild # 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( async def api_return_image(