diff --git a/api/advent22_api/core/advent_image.py b/api/advent22_api/core/advent_image.py index 74003d2..8bc5fc4 100644 --- a/api/advent22_api/core/advent_image.py +++ b/api/advent22_api/core/advent_image.py @@ -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, ) ) diff --git a/api/advent22_api/core/config.py b/api/advent22_api/core/config.py index ac8d23c..18af325 100644 --- a/api/advent22_api/core/config.py +++ b/api/advent22_api/core/config.py @@ -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 diff --git a/api/advent22_api/core/depends.py b/api/advent22_api/core/depends.py index e4d0a3d..22da00a 100644 --- a/api/advent22_api/core/depends.py +++ b/api/advent22_api/core/depends.py @@ -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: