from PIL import Image def png_to_ico(input_file_path, output_file_path): try: image = Image.open(input_file_path) if image.mode != "RGBA": image = image.convert("RGBA") image.save(output_file_path, format="ICO") print("转换成功!") except Exception as e: print("转换失败:", e) # 使用示例: input_path = "logoico.png" output_path = "favicon.ico" png_to_ico(input_path, output_path)
将代码保存为*.py文件
然后可以使用python“运行”,前提是安装python环境
python *.py
运行结果