Kimi生成
from PIL import Image
def generate_icon(source_image_path, output_image_path, size):
with Image.open(source_image_path) as img:
# 转换图片为RGBA模式,确保有透明通道
if img.mode != 'RGBA':
img = img.convert('RGBA')
# 调整图片大小到指定尺寸
img = img.resize((size, size), Image.ANTIALIAS)
# 保存为PNG格式
img.save(output_image_path)
if __name__ == "__main__":
# 源PNG文件路径
source_image_path = 'g.png'
# 输出图标尺寸列表
icon_sizes = [16, 32, 48, 128]
# 遍历尺寸列表,生成不同尺寸的图标
for size in icon_sizes:
# 定义输出文件路径,包含尺寸
output_image_path = f'icon_{size}x{size}.png'
# 生成图标
generate_icon(source_image_path, output_image_path, size)
print(f'Generated {output_image_path}')