131 lines
4.5 KiB
Python
131 lines
4.5 KiB
Python
#!/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 = """
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>图标预览</title>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; padding: 20px; }
|
|
.icon-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 20px; }
|
|
.icon-item { text-align: center; }
|
|
.icon-name { margin-top: 10px; font-size: 14px; color: #333; }
|
|
.icon-pair { display: flex; flex-direction: column; align-items: center; gap: 10px; }
|
|
.icon-label { font-size: 12px; color: #666; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>底部导航图标预览</h1>
|
|
<div class="icon-grid">
|
|
"""
|
|
|
|
for name in ICONS.keys():
|
|
html_content += f"""
|
|
<div class="icon-item">
|
|
<div class="icon-pair">
|
|
<div class="icon-label">默认</div>
|
|
<img src="{name}.png" alt="{name}" width="48" height="48">
|
|
<div class="icon-label">激活</div>
|
|
<img src="{name}-active.png" alt="{name}-active" width="48" height="48">
|
|
</div>
|
|
<div class="icon-name">{name}</div>
|
|
</div>
|
|
"""
|
|
|
|
html_content += """
|
|
</div>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
preview_path = os.path.join(icon_dir, 'preview.html')
|
|
with open(preview_path, 'w', encoding='utf-8') as f:
|
|
f.write(html_content)
|
|
|
|
print(f"预览文件: {preview_path}")
|
|
|
|
if __name__ == '__main__':
|
|
main() |