From 13255dcb55fe5fc71eb5db2bd75671458141f221 Mon Sep 17 00:00:00 2001 From: quqiOnfree Date: Tue, 26 Aug 2025 03:45:48 +0800 Subject: [PATCH] Fix bugs --- create_image.py | 10 ++++++---- main.py | 2 +- motd_formatter.py | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/create_image.py b/create_image.py index 5a6f8be..d09f7d8 100644 --- a/create_image.py +++ b/create_image.py @@ -33,12 +33,14 @@ def draw_motd_text_with_shadow(image: Image.Image, text: str, posx: int, posy: i font_size = 10 draw = ImageDraw.Draw(image) font = ImageFont.truetype("./MiSans-Bold.ttf", font_size) - w1, _, w2, _ = draw.textbbox((0, 0), text, font=font) + w1, _, w2, _ = draw.textbbox((0, 0), text.strip(), font=font) weight = w2 - w1 - motd_list = foramt_motd(text, weight) + motd_list = foramt_motd(text.strip(), weight) for pos, color, text in motd_list: - draw.text((posx + pos + 1, posy + 1), text, font=font, fill='black') - draw.text((posx + pos, posy), text, font=font, fill=getrgb(color)) + w1, _, w2, _ = draw.textbbox((0, 0), text, font=font) + weight = w2 - w1 + draw.text((posx + pos + 1 - weight, posy + 1), text, font=font, fill='black') + draw.text((posx + pos - weight, posy), text, font=font, fill=getrgb(color)) def create_image(background: bytes, icon: str | None, text_list: list[str], motd_list: list[str]): # 图片尺寸 diff --git a/main.py b/main.py index 3237231..e4940b0 100644 --- a/main.py +++ b/main.py @@ -45,4 +45,4 @@ def generate_java_status_image(addr: str): if __name__ == "__main__": image = generate_java_status_image("mc.hypixel.net") if image: - image.save("output_image.png") \ No newline at end of file + image.save("output_image.png") diff --git a/motd_formatter.py b/motd_formatter.py index 76ccccb..9ba2aab 100644 --- a/motd_formatter.py +++ b/motd_formatter.py @@ -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": text += data[iter] iter += 1 - motd_list.append((len(text), "white", text)) + motd_list.append(((iter - character_count * 2) / data_size * weight, "white", text)) return motd_list