mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 08:13:01 +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
|
import colorsys
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Self
|
from typing import Self, TypeAlias, cast
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
|
_RGB: TypeAlias = tuple[int, int, int]
|
||||||
|
_XY: TypeAlias = tuple[float, float]
|
||||||
|
|
||||||
|
|
||||||
@dataclass(slots=True, frozen=True)
|
@dataclass(slots=True, frozen=True)
|
||||||
class AdventImage:
|
class AdventImage:
|
||||||
|
@ -43,7 +46,7 @@ class AdventImage:
|
||||||
|
|
||||||
async def get_text_box(
|
async def get_text_box(
|
||||||
self,
|
self,
|
||||||
xy: tuple[float, float],
|
xy: _XY,
|
||||||
text: str | bytes,
|
text: str | bytes,
|
||||||
font: "ImageFont._Font",
|
font: "ImageFont._Font",
|
||||||
anchor: str | None = "mm",
|
anchor: str | None = "mm",
|
||||||
|
@ -81,13 +84,13 @@ class AdventImage:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pixel_data = self.img.crop(box).getdata()
|
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(
|
async def hide_text(
|
||||||
self,
|
self,
|
||||||
xy: tuple[float, float],
|
xy: _XY,
|
||||||
text: str | bytes,
|
text: str | bytes,
|
||||||
font: "ImageFont._Font",
|
font: "ImageFont._Font",
|
||||||
anchor: str | None = "mm",
|
anchor: str | None = "mm",
|
||||||
|
@ -127,7 +130,7 @@ class AdventImage:
|
||||||
xy=xy,
|
xy=xy,
|
||||||
text=text,
|
text=text,
|
||||||
font=font,
|
font=font,
|
||||||
fill=text_color,
|
fill=cast(_RGB, text_color),
|
||||||
anchor=anchor,
|
anchor=anchor,
|
||||||
**text_kwargs,
|
**text_kwargs,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue