This commit is contained in:
quqiOnfree 2025-08-26 03:45:48 +08:00
parent 0effcb90d5
commit 13255dcb55
3 changed files with 8 additions and 6 deletions

View file

@ -33,12 +33,14 @@ def draw_motd_text_with_shadow(image: Image.Image, text: str, posx: int, posy: i
font_size = 10 font_size = 10
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
font = ImageFont.truetype("./MiSans-Bold.ttf", font_size) font = ImageFont.truetype("./MiSans-Bold.ttf", font_size)
w1, _, w2, _ = draw.textbbox((0, 0), text.strip(), font=font)
weight = w2 - w1
motd_list = foramt_motd(text.strip(), weight)
for pos, color, text in motd_list:
w1, _, w2, _ = draw.textbbox((0, 0), text, font=font) w1, _, w2, _ = draw.textbbox((0, 0), text, font=font)
weight = w2 - w1 weight = w2 - w1
motd_list = foramt_motd(text, weight) draw.text((posx + pos + 1 - weight, posy + 1), text, font=font, fill='black')
for pos, color, text in motd_list: draw.text((posx + pos - weight, posy), text, font=font, fill=getrgb(color))
draw.text((posx + pos + 1, posy + 1), text, font=font, fill='black')
draw.text((posx + pos, posy), text, font=font, fill=getrgb(color))
def create_image(background: bytes, icon: str | None, text_list: list[str], motd_list: list[str]): def create_image(background: bytes, icon: str | None, text_list: list[str], motd_list: list[str]):
# 图片尺寸 # 图片尺寸

View file

@ -65,5 +65,5 @@ def foramt_motd(data: str, weight: int) -> list[tuple[int, str, str]]:
while iter < data_size and data[iter] != "§" and data[iter] != "\n": while iter < data_size and data[iter] != "§" and data[iter] != "\n":
text += data[iter] text += data[iter]
iter += 1 iter += 1
motd_list.append((len(text), "white", text)) motd_list.append(((iter - character_count * 2) / data_size * weight, "white", text))
return motd_list return motd_list