Files
xianyan/scripts/resize_icon.py
Developer 7564e8893d chore: 完成多平台适配与代码优化
此提交包含多项变更:
1. 新增鸿蒙平台支持,完善设备检测与数据库适配
2. 替换旧版分享插件API为SharePlus
3. 批量迁移StateNotifier到Notifier以适配新版Riverpod
4. 修复zip编码判断、图表API参数等bug
5. 更新应用图标、启动页资源与多尺寸适配图标
6. 调整Android最小SDK版本与应用名称
7. 优化日志打印与正则表达式使用
8. 修正编辑器画布样式初始化与配置逻辑
9. 更新依赖与CI插件配置
2026-05-17 07:17:07 +08:00

103 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
"""
@创建时间: 2026-05-16
@更新时间: 2026-05-16
@名称: resize_icon.py
@作用: 将源图片裁剪为从16x16到1024x1024的常用尺寸图标
@上次更新内容: 初始创建
"""
import os
from PIL import Image
SOURCE_IMAGE = os.path.join(os.path.dirname(__file__), "..", "assets", "templates", "xianyan.png")
OUTPUT_DIR = os.path.join(os.path.dirname(__file__), "..", "assets", "templates", "resized")
SIZES = [
16,
20,
24,
29,
32,
40,
48,
50,
57,
58,
60,
64,
72,
76,
80,
87,
88,
96,
100,
114,
120,
128,
144,
152,
167,
180,
192,
216,
256,
512,
1024,
]
SIZE_CATEGORIES = {
"favicon": [16, 32],
"ios_notification": [20],
"ios_settings": [29],
"ios_spotlight": [40],
"ios_app": [60, 76, 87, 120, 152, 167, 180, 1024],
"android_launcher": [48, 72, 96, 144, 192, 216],
"web_app": [64, 128, 256, 512],
"general": [24, 50, 57, 58, 80, 88, 100, 114],
}
def resize_image(source_path: str, output_dir: str, size: int) -> str:
img = Image.open(source_path)
if img.mode != "RGBA":
img = img.convert("RGBA")
resized = img.resize((size, size), Image.LANCZOS)
filename = f"icon_{size}x{size}.png"
filepath = os.path.join(output_dir, filename)
resized.save(filepath, "PNG", compress_level=0)
return filename
def main():
source_path = os.path.normpath(SOURCE_IMAGE)
output_dir = os.path.normpath(OUTPUT_DIR)
if not os.path.exists(source_path):
print(f"[ERROR] Source image not found: {source_path}")
return
os.makedirs(output_dir, exist_ok=True)
print(f"Source: {source_path}")
print(f"Output: {output_dir}")
print(f"Sizes: {len(SIZES)} variants\n")
for size in SIZES:
filename = resize_image(source_path, output_dir, size)
print(f" [OK] {filename}")
print(f"\nDone! {len(SIZES)} icons generated in: {output_dir}")
print("\n--- Size Category Reference ---")
for category, sizes in SIZE_CATEGORIES.items():
matching = [s for s in sizes if s in SIZES]
if matching:
print(f" {category}: {', '.join(f'{s}x{s}' for s in matching)}")
if __name__ == "__main__":
main()