From 4485213713c5a78f407e719e605f018c281c9851 Mon Sep 17 00:00:00 2001 From: quqiOnfree Date: Tue, 2 Sep 2025 13:09:40 +0800 Subject: [PATCH] trim --- create_image.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/create_image.py b/create_image.py index a1602a1..4b31fa5 100644 --- a/create_image.py +++ b/create_image.py @@ -1,7 +1,13 @@ from PIL import Image, ImageDraw, ImageFont, ImageFilter from io import BytesIO -from motd_formatter import foramt_motd from PIL.ImageColor import getrgb +import asyncio + +from .motd_formatter import foramt_motd +from .get_background import download_image_with_httpx_auto_redirect + +BACKGROUND_URL = "https://www.loliapi.com/acg/" +DEFAULT_ICON = "./minecraft-creeper-face.png" def create_background(input: bytes, width: int, height: int): background = Image.open(BytesIO(input)) @@ -103,3 +109,17 @@ def create_image(background: bytes, font_size) return image + +async def get_icon_image(url: str): + if url.startswith("http"): + icon_data = await download_image_with_httpx_auto_redirect(url) + if icon_data: + return icon_data + else: + return None + else: + def read_file(path): + with open(path, "rb") as f: + return f.read() + loop = asyncio.get_event_loop() + return await loop.run_in_executor(None, read_file, url)