From f704cb4910414049229b20b6fe141a6e367212b0 Mon Sep 17 00:00:00 2001 From: mei Date: Thu, 31 Jul 2025 08:01:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20convert=5Ficon.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convert_icon.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 convert_icon.py diff --git a/convert_icon.py b/convert_icon.py new file mode 100644 index 0000000..6a3163b --- /dev/null +++ b/convert_icon.py @@ -0,0 +1,33 @@ +from PIL import Image +import sys +import os + +def convert_to_minecraft_icon(input_path, output_path="server-icon.png"): + try: + with Image.open(input_path) as img: + # 将图片转为RGBA模式(确保透明度兼容性) + img = img.convert("RGBA") + + # 获取最小边长,中心裁剪为正方形 + min_side = min(img.size) + left = (img.width - min_side) // 2 + top = (img.height - min_side) // 2 + right = left + min_side + bottom = top + min_side + img_cropped = img.crop((left, top, right, bottom)) + + # 缩放为64x64像素 + img_resized = img_cropped.resize((64, 64), Image.LANCZOS) + + # 保存为PNG格式 + img_resized.save(output_path, format="PNG") + print(f"✔ 成功生成 Minecraft 服务器图标: {output_path}") + + except Exception as e: + print(f"❌ 处理失败: {e}") + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("用法: python convert_icon.py <输入图片路径>") + else: + convert_to_minecraft_icon(sys.argv[1])