mirror of
https://github.com/Murasame-Dev/McStatus-Img.git
synced 2025-12-16 13:17:40 +00:00
trim
This commit is contained in:
parent
4485213713
commit
fd80315876
2 changed files with 19 additions and 19 deletions
|
|
@ -1,13 +1,8 @@
|
||||||
from PIL import Image, ImageDraw, ImageFont, ImageFilter
|
from PIL import Image, ImageDraw, ImageFont, ImageFilter
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from PIL.ImageColor import getrgb
|
from PIL.ImageColor import getrgb
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from .motd_formatter import foramt_motd
|
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):
|
def create_background(input: bytes, width: int, height: int):
|
||||||
background = Image.open(BytesIO(input))
|
background = Image.open(BytesIO(input))
|
||||||
|
|
@ -109,17 +104,3 @@ def create_image(background: bytes,
|
||||||
font_size)
|
font_size)
|
||||||
|
|
||||||
return image
|
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)
|
|
||||||
|
|
|
||||||
19
get_icon.py
Normal file
19
get_icon.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
from .get_background import download_image_with_httpx_auto_redirect
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
# BACKGROUND_URL = "https://www.loliapi.com/acg/"
|
||||||
|
# DEFAULT_ICON = "./minecraft-creeper-face.png"
|
||||||
|
|
||||||
|
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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue