#!/usr/bin/env python3 """ 创建简单的底部导航图标 由于无法下载,我们创建简单的彩色圆形图标 """ from PIL import Image, ImageDraw import os # 图标尺寸 SIZE = 48 # 48x48像素 # 图标颜色配置 ICONS = { # 默认状态颜色 'home': {'color': '#7A7E83', 'active': '#3cc51f', 'text': '🏠'}, 'project': {'color': '#7A7E83', 'active': '#3cc51f', 'text': '📦'}, 'wechat': {'color': '#7A7E83', 'active': '#3cc51f', 'text': '📱'}, 'tree': {'color': '#7A7E83', 'active': '#3cc51f', 'text': '🌳'}, 'mine': {'color': '#7A7E83', 'active': '#3cc51f', 'text': '👤'}, } def create_icon(name, color, is_active=False): """创建图标""" # 创建新图像 img = Image.new('RGBA', (SIZE, SIZE), (255, 255, 255, 0)) draw = ImageDraw.Draw(img) # 绘制圆形背景 circle_color = color if is_active else ICONS[name]['color'] draw.ellipse([4, 4, SIZE-4, SIZE-4], fill=circle_color) # 绘制文字(使用emoji或简单图形) # 这里我们使用简单的图形代替 if name == 'home': # 房子图标 draw.rectangle([SIZE//2-8, SIZE//2-4, SIZE//2+8, SIZE//2+4], fill='white') draw.polygon([ (SIZE//2-10, SIZE//2-4), (SIZE//2, SIZE//2-12), (SIZE//2+10, SIZE//2-4) ], fill='white') elif name == 'project': # 盒子图标 draw.rectangle([SIZE//2-10, SIZE//2-8, SIZE//2+10, SIZE//2+8], fill='white') draw.line([SIZE//2-10, SIZE//2-8, SIZE//2-10, SIZE//2+8], fill='white', width=2) draw.line([SIZE//2+10, SIZE//2-8, SIZE//2+10, SIZE//2+8], fill='white', width=2) elif name == 'wechat': # 微信/公众号图标 draw.ellipse([SIZE//2-12, SIZE//2-8, SIZE//2-4, SIZE//2], fill='white') draw.ellipse([SIZE//2+4, SIZE//2-8, SIZE//2+12, SIZE//2], fill='white') elif name == 'tree': # 树形图标 draw.rectangle([SIZE//2-2, SIZE//2, SIZE//2+2, SIZE//2+8], fill='white') draw.ellipse([SIZE//2-8, SIZE//2-10, SIZE//2+8, SIZE//2+2], fill='white') elif name == 'mine': # 人头图标 draw.ellipse([SIZE//2-8, SIZE//2-10, SIZE//2+8, SIZE//2+6], fill='white') draw.ellipse([SIZE//2-4, SIZE//2-8, SIZE//2+4, SIZE//2], fill=circle_color) return img def main(): """主函数""" icon_dir = 'static/images/icons' os.makedirs(icon_dir, exist_ok=True) print("创建底部导航图标...") for name, config in ICONS.items(): # 创建默认图标 default_img = create_icon(name, config['color'], is_active=False) default_path = os.path.join(icon_dir, f'{name}.png') default_img.save(default_path) print(f"创建: {default_path}") # 创建激活图标 active_img = create_icon(name, config['active'], is_active=True) active_path = os.path.join(icon_dir, f'{name}-active.png') active_img.save(active_path) print(f"创建: {active_path}") print("✅ 图标创建完成!") # 创建预览HTML html_content = """