- 电脑安装图片处理工具
ImageMagick
: https://imagemagick.org/index.php - Python 环境安装用于调用
ImageMagick API
的 Wand
库: pip install Wand
- 示例代码:
import os
from wand.color import Color
from wand.image import Image
def img_to_ico(src_img_path, output_ico_path):
ico = Image(filename=src_img_path, background=Color("transparent"))
for size in ((64, 64), (48, 48), (32, 32), (16, 16)):
img = Image(width=size[0], height=size[1], filename=src_img_path, background=Color("transparent"))
ico.sequence.append(img)
if not os.path.exists(os.path.dirname(output_ico_path)):
os.makedirs(os.path.dirname(output_ico_path))
ico.save(filename=output_ico_path)
if __name__ == '__main__':
img_to_ico("D:\\apple.svg", "D:\\apple.ico")