mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
refactoring
This commit is contained in:
@@ -26,7 +26,7 @@ import functools
|
|||||||
from aiohttp.web import Request
|
from aiohttp.web import Request
|
||||||
from aiohttp.web import Response
|
from aiohttp.web import Response
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image as PilImage
|
||||||
|
|
||||||
from ....validators.basic import valid_bool
|
from ....validators.basic import valid_bool
|
||||||
from ....validators.basic import valid_int_f0
|
from ....validators.basic import valid_int_f0
|
||||||
@@ -104,7 +104,7 @@ class StreamerApi:
|
|||||||
assert not (max_width == snapshot.width and max_height == snapshot.height)
|
assert not (max_width == snapshot.width and max_height == snapshot.height)
|
||||||
with io.BytesIO(snapshot.data) as snapshot_bio:
|
with io.BytesIO(snapshot.data) as snapshot_bio:
|
||||||
with io.BytesIO() as preview_bio:
|
with io.BytesIO() as preview_bio:
|
||||||
with Image.open(snapshot_bio) as image:
|
with PilImage.open(snapshot_bio) as image:
|
||||||
image.thumbnail((max_width, max_height), Image.ANTIALIAS)
|
image.thumbnail((max_width, max_height), PilImage.ANTIALIAS)
|
||||||
image.save(preview_bio, format="jpeg", quality=quality)
|
image.save(preview_bio, format="jpeg", quality=quality)
|
||||||
return preview_bio.getvalue()
|
return preview_bio.getvalue()
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ import os
|
|||||||
import io
|
import io
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image as PilImage
|
||||||
from PIL import ImageDraw
|
from PIL import ImageDraw as PilImageDraw
|
||||||
from PIL import ImageFont
|
from PIL import ImageFont as PilImageFont
|
||||||
|
|
||||||
from ... import aiotools
|
from ... import aiotools
|
||||||
|
|
||||||
@@ -39,8 +39,8 @@ async def make_text_jpeg(width: int, height: int, quality: int, text: str) -> by
|
|||||||
|
|
||||||
@functools.lru_cache(maxsize=10)
|
@functools.lru_cache(maxsize=10)
|
||||||
def _inner_make_text_jpeg(width: int, height: int, quality: int, text: str) -> bytes:
|
def _inner_make_text_jpeg(width: int, height: int, quality: int, text: str) -> bytes:
|
||||||
image = Image.new("RGB", (width, height), color=(0, 0, 0))
|
image = PilImage.new("RGB", (width, height), color=(0, 0, 0))
|
||||||
draw = ImageDraw.Draw(image)
|
draw = PilImageDraw.Draw(image)
|
||||||
draw.multiline_text((20, 20), text, font=_get_font(), fill=(255, 255, 255))
|
draw.multiline_text((20, 20), text, font=_get_font(), fill=(255, 255, 255))
|
||||||
with io.BytesIO() as bio:
|
with io.BytesIO() as bio:
|
||||||
image.save(bio, format="jpeg", quality=quality)
|
image.save(bio, format="jpeg", quality=quality)
|
||||||
@@ -48,8 +48,8 @@ def _inner_make_text_jpeg(width: int, height: int, quality: int, text: str) -> b
|
|||||||
|
|
||||||
|
|
||||||
@functools.lru_cache()
|
@functools.lru_cache()
|
||||||
def _get_font() -> ImageFont.FreeTypeFont:
|
def _get_font() -> PilImageFont.FreeTypeFont:
|
||||||
module_path = sys.modules[__name__].__file__
|
module_path = sys.modules[__name__].__file__
|
||||||
assert module_path is not None
|
assert module_path is not None
|
||||||
path = os.path.join(os.path.dirname(module_path), "fonts", "Azbuka04.ttf")
|
path = os.path.join(os.path.dirname(module_path), "fonts", "Azbuka04.ttf")
|
||||||
return ImageFont.truetype(path, size=20)
|
return PilImageFont.truetype(path, size=20)
|
||||||
|
|||||||
Reference in New Issue
Block a user