Files
Any2MIF/create_icon.py
2025-03-07 15:32:58 +08:00

43 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2025 Any2MIF Project
# All rights reserved.
"""
Any2MIF - 图标生成脚本
创建一个简单的图标文件,用于打包时使用
"""
import os
from PIL import Image, ImageDraw, ImageFont
def create_icon():
"""创建一个简单的图标文件"""
# 创建一个32x32像素的图像背景为透明
img = Image.new('RGBA', (256, 256), color=(0, 0, 0, 0))
draw = ImageDraw.Draw(img)
# 绘制一个圆形背景
draw.ellipse((16, 16, 240, 240), fill=(41, 128, 185))
# 绘制文字
try:
# 尝试加载系统字体
font = ImageFont.truetype("arial.ttf", 120)
except IOError:
# 如果无法加载系统字体,使用默认字体
font = ImageFont.load_default()
# 绘制"A2M"文字
draw.text((50, 70), "AM", fill=(255, 255, 255), font=font)
# 确保resources目录存在
if not os.path.exists("resources"):
os.makedirs("resources")
# 保存为.ico文件
img.save("resources/icon.ico", format="ICO", sizes=[(16, 16), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)])
print(f"图标文件已创建:{os.path.abspath('resources/icon.ico')}")
if __name__ == "__main__":
create_icon()