Skip to content

Commit

Permalink
[BattleRoyale] use my own type
Browse files Browse the repository at this point in the history
  • Loading branch information
japandotorg committed Jul 21, 2024
1 parent 07ebf7f commit fe8f12b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions battleroyale/models/_pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@

# much of this code has been taken from https://github.com/shahriyardx/easy-pil/tree/master

import io
from io import BytesIO
from os import PathLike
from pathlib import Path
from typing import Any, Dict, Literal, Optional, Tuple, Union

from PIL import Image, ImageDraw, ImageFont, _typing
from PIL import Image, ImageDraw, ImageFont

Color = Union[int, str, Tuple[int, int, int], Tuple[int, int, int, int]]

StrOrBytesPath = Union[str, bytes, PathLike[str], PathLike[bytes]]


class Font:
def __init__(self, path: str, size: int = 10, **kwargs: Any) -> None:
Expand Down Expand Up @@ -101,8 +103,8 @@ def __init__(self, _image: Union[Image.Image, str, BytesIO, "Editor", Canvas, Pa
self.image: Image.Image = self.image.convert("RGBA")

@property
def image_bytes(self) -> io.BytesIO:
_bytes: io.BytesIO = io.BytesIO()
def image_bytes(self) -> BytesIO:
_bytes: BytesIO = BytesIO()
self.image.save(_bytes, "png", optimize=True)
_bytes.seek(0)
return _bytes
Expand All @@ -111,7 +113,7 @@ def show(self) -> None:
self.image.show()

def save(
self, fp: _typing.StrOrBytesPath, file_format: Optional[str] = None, **params: Any
self, fp: StrOrBytesPath, file_format: Optional[str] = None, **params: Any
) -> None:
self.image.save(fp, file_format, **params)

Expand Down

0 comments on commit fe8f12b

Please sign in to comment.