icon优化
This commit is contained in:
52
resize_icons.py
Normal file
52
resize_icons.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from PIL import Image
|
||||
import os
|
||||
|
||||
# 原始图片路径
|
||||
original_image_path = r"e:\project\flutter\f3\flutter_application_2\assets\audios\IMG_20260402_170051.png"
|
||||
|
||||
# 输出目录
|
||||
app_scope_dir = r"e:\project\flutter\f3\flutter_application_2\ohos\AppScope\resources\base\media"
|
||||
entry_media_dir = r"e:\project\flutter\f3\flutter_application_2\ohos\entry\src\main\resources\base\media"
|
||||
|
||||
# 确保目录存在
|
||||
os.makedirs(app_scope_dir, exist_ok=True)
|
||||
os.makedirs(entry_media_dir, exist_ok=True)
|
||||
|
||||
try:
|
||||
# 打开原始图片
|
||||
with Image.open(original_image_path) as img:
|
||||
print(f"原始图片尺寸: {img.size}")
|
||||
|
||||
# 调整为 288x288 用于 app_icon.png
|
||||
img_288 = img.resize((288, 288), Image.Resampling.LANCZOS)
|
||||
app_icon_path = os.path.join(app_scope_dir, "app_icon.png")
|
||||
img_288.save(app_icon_path)
|
||||
print(f"已保存 288x288 图标到: {app_icon_path}")
|
||||
|
||||
# 调整为 1024x1024 用于 entry 目录的图标
|
||||
img_1024 = img.resize((1024, 1024), Image.Resampling.LANCZOS)
|
||||
|
||||
# 保存到 entry 目录
|
||||
entry_icon_path = os.path.join(entry_media_dir, "icon.png")
|
||||
img_1024.save(entry_icon_path)
|
||||
print(f"已保存 1024x1024 图标到: {entry_icon_path}")
|
||||
|
||||
# 保存其他尺寸
|
||||
sizes = [
|
||||
(216, "icon_216.png"),
|
||||
(48, "icon_48.png"),
|
||||
(512, "icon_512.png"),
|
||||
(72, "icon_72.png"),
|
||||
(96, "icon_96.png"),
|
||||
]
|
||||
|
||||
for size, filename in sizes:
|
||||
resized_img = img.resize((size, size), Image.Resampling.LANCZOS)
|
||||
output_path = os.path.join(entry_media_dir, filename)
|
||||
resized_img.save(output_path)
|
||||
print(f"已保存 {size}x{size} 图标到: {output_path}")
|
||||
|
||||
print("\n所有图标尺寸调整完成!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"处理图片时出错: {e}")
|
||||
Reference in New Issue
Block a user