mirror of
https://github.com/Murasame-Dev/McStatus-Img.git
synced 2025-12-16 13:17:40 +00:00
Trim some code
This commit is contained in:
parent
928e333e6b
commit
a37b9d14f2
1 changed files with 4 additions and 6 deletions
|
|
@ -31,7 +31,6 @@ def draw_text_with_shadow(image: Image.Image,
|
||||||
text: str,
|
text: str,
|
||||||
posx: int,
|
posx: int,
|
||||||
posy: int,
|
posy: int,
|
||||||
font_size: int,
|
|
||||||
font):
|
font):
|
||||||
draw = ImageDraw.Draw(image)
|
draw = ImageDraw.Draw(image)
|
||||||
draw.text((posx + 2, posy + 2), text, font=font, fill='black')
|
draw.text((posx + 2, posy + 2), text, font=font, fill='black')
|
||||||
|
|
@ -41,7 +40,6 @@ def draw_motd_text_with_shadow(image: Image.Image,
|
||||||
text: str,
|
text: str,
|
||||||
posx: int,
|
posx: int,
|
||||||
posy: int,
|
posy: int,
|
||||||
font_size: int,
|
|
||||||
font):
|
font):
|
||||||
draw = ImageDraw.Draw(image)
|
draw = ImageDraw.Draw(image)
|
||||||
w1, _, w2, _ = draw.textbbox((0, 0), text.strip(), font=font)
|
w1, _, w2, _ = draw.textbbox((0, 0), text.strip(), font=font)
|
||||||
|
|
@ -58,14 +56,16 @@ def create_image(background: bytes,
|
||||||
text_list: list[str],
|
text_list: list[str],
|
||||||
motd_list: list[str],
|
motd_list: list[str],
|
||||||
font_url: str | None,
|
font_url: str | None,
|
||||||
image_size: list[int]):
|
image_size: list[int] = [0, 0]):
|
||||||
# 图片尺寸
|
# 图片尺寸
|
||||||
if image_size == [0, 0] or image_size == []:
|
if image_size == [0, 0] or image_size == []:
|
||||||
width = 1200
|
width = 1200
|
||||||
height = 400
|
height = 400
|
||||||
else:
|
elif len(image_size) == 2:
|
||||||
width = image_size[0]
|
width = image_size[0]
|
||||||
height = image_size[1]
|
height = image_size[1]
|
||||||
|
else:
|
||||||
|
assert ValueError("image_size is invalid")
|
||||||
|
|
||||||
if (len(text_list) + len(motd_list)) * 20 + 20 > height:
|
if (len(text_list) + len(motd_list)) * 20 + 20 > height:
|
||||||
height = (len(text_list) + len(motd_list)) * 20 + 20
|
height = (len(text_list) + len(motd_list)) * 20 + 20
|
||||||
|
|
@ -109,14 +109,12 @@ def create_image(background: bytes,
|
||||||
motd_list[i],
|
motd_list[i],
|
||||||
width // 2.5,
|
width // 2.5,
|
||||||
start_posy + font_size * 1.2 * i,
|
start_posy + font_size * 1.2 * i,
|
||||||
int(font_size * 0.8),
|
|
||||||
font)
|
font)
|
||||||
for i in range(text_list_size):
|
for i in range(text_list_size):
|
||||||
draw_text_with_shadow(image,
|
draw_text_with_shadow(image,
|
||||||
text_list[i],
|
text_list[i],
|
||||||
width // 2.5,
|
width // 2.5,
|
||||||
start_posy + font_size * 1.2 * (i + motd_list_size),
|
start_posy + font_size * 1.2 * (i + motd_list_size),
|
||||||
font_size,
|
|
||||||
font)
|
font)
|
||||||
|
|
||||||
return image
|
return image
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue