mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-26 17:33:00 +00:00
typing issues
This commit is contained in:
parent
c8ce12c299
commit
74688f45b8
1 changed files with 9 additions and 6 deletions
|
@ -1,10 +1,13 @@
|
|||
import colorsys
|
||||
from dataclasses import dataclass
|
||||
from typing import Self
|
||||
from typing import Self, TypeAlias, cast
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
_RGB: TypeAlias = tuple[int, int, int]
|
||||
_XY: TypeAlias = tuple[float, float]
|
||||
|
||||
|
||||
@dataclass(slots=True, frozen=True)
|
||||
class AdventImage:
|
||||
|
@ -43,7 +46,7 @@ class AdventImage:
|
|||
|
||||
async def get_text_box(
|
||||
self,
|
||||
xy: tuple[float, float],
|
||||
xy: _XY,
|
||||
text: str | bytes,
|
||||
font: "ImageFont._Font",
|
||||
anchor: str | None = "mm",
|
||||
|
@ -81,13 +84,13 @@ class AdventImage:
|
|||
"""
|
||||
|
||||
pixel_data = self.img.crop(box).getdata()
|
||||
mean_color: np.ndarray = np.mean(a=pixel_data, axis=0)
|
||||
mean_color: np.ndarray = np.mean(pixel_data, axis=0)
|
||||
|
||||
return tuple(mean_color.astype(int)[:3])
|
||||
return cast(_RGB, tuple(mean_color.astype(int)))
|
||||
|
||||
async def hide_text(
|
||||
self,
|
||||
xy: tuple[float, float],
|
||||
xy: _XY,
|
||||
text: str | bytes,
|
||||
font: "ImageFont._Font",
|
||||
anchor: str | None = "mm",
|
||||
|
@ -127,7 +130,7 @@ class AdventImage:
|
|||
xy=xy,
|
||||
text=text,
|
||||
font=font,
|
||||
fill=text_color,
|
||||
fill=cast(_RGB, text_color),
|
||||
anchor=anchor,
|
||||
**text_kwargs,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue