mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-12-23 13:13:00 +00:00
Todo 2
This commit is contained in:
parent
337d8d34ff
commit
84c5467edb
3 changed files with 8 additions and 7 deletions
|
@ -5,6 +5,8 @@ from typing import Self, TypeAlias, cast
|
|||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
from .config import Config
|
||||
|
||||
_RGB: TypeAlias = tuple[int, int, int]
|
||||
_XY: TypeAlias = tuple[float, float]
|
||||
|
||||
|
@ -14,7 +16,7 @@ class AdventImage:
|
|||
img: Image.Image
|
||||
|
||||
@classmethod
|
||||
async def from_img(cls, img: Image.Image) -> Self:
|
||||
async def from_img(cls, img: Image.Image, cfg: Config) -> Self:
|
||||
"""
|
||||
Einen quadratischen Ausschnitt aus der Mitte des Bilds nehmen
|
||||
"""
|
||||
|
@ -39,7 +41,7 @@ class AdventImage:
|
|||
# skalieren
|
||||
return cls(
|
||||
img.resize(
|
||||
size=(1000, 1000),
|
||||
size=(cfg.image.size, cfg.image.size),
|
||||
resample=Image.LANCZOS,
|
||||
)
|
||||
)
|
||||
|
|
|
@ -97,11 +97,9 @@ class TTFont(BaseModel):
|
|||
|
||||
class Image(BaseModel):
|
||||
# Quadrat, Seitenlänge in px
|
||||
# TODO penner
|
||||
size: int = 1000
|
||||
|
||||
# Rand in px, wo keine Buchstaben untergebracht werden
|
||||
# TODO penner
|
||||
border: int = 60
|
||||
|
||||
# Schriftarten
|
||||
|
|
|
@ -109,7 +109,7 @@ async def gen_day_auto_image(
|
|||
|
||||
# Datei existiert garantiert!
|
||||
img = await load_image(auto_image_names[day])
|
||||
image = await AdventImage.from_img(img)
|
||||
image = await AdventImage.from_img(img, cfg)
|
||||
|
||||
rnd = await Random.get(day)
|
||||
|
||||
|
@ -120,8 +120,9 @@ async def gen_day_auto_image(
|
|||
|
||||
# Buchstaben verstecken
|
||||
for letter in day_parts[day]:
|
||||
xy_range = range(cfg.image.border, (cfg.image.size - cfg.image.border))
|
||||
await image.hide_text(
|
||||
xy=cast(_XY, tuple(rnd.choices(range(60, 940), k=2))),
|
||||
xy=cast(_XY, tuple(rnd.choices(xy_range, k=2))),
|
||||
text=letter,
|
||||
font=font,
|
||||
)
|
||||
|
@ -148,7 +149,7 @@ async def get_day_image(
|
|||
img = await load_image(f"images_manual/{day}.jpg")
|
||||
|
||||
# Als AdventImage verarbeiten
|
||||
image = await AdventImage.from_img(img)
|
||||
image = await AdventImage.from_img(img, cfg)
|
||||
return image.img
|
||||
|
||||
except RuntimeError:
|
||||
|
|
Loading…
Reference in a new issue