Config.puzzle.font
This commit is contained in:
parent
05750d6de2
commit
17b6950491
2 changed files with 14 additions and 6 deletions
|
@ -12,6 +12,7 @@ class User(BaseModel):
|
|||
|
||||
class Puzzle(BaseModel):
|
||||
background: str
|
||||
font: str
|
||||
solution: str
|
||||
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue