正如您所提到的,您只需将徽标从 jpg 转换为相应操作系统的图标文件,然后尝试Pillow 的图像转换器。
此代码将为所有(Mac、Win、Linux)生成图标文件
from PIL import Image
filename = r'logo.jpg' # the directory of logo file
img = Image.open(filename) # reads the JPG file
# Generate and save the logo files
img.save('Win_logo.ico') # On windows, icon file extension is .ico
img.save('Mac_logo.icns') # On Mac OS, icon file extension is .icns
# Note: Creating icns requires Mac OS
img.save('Linux_logo.png') # in case if your AppImage requires any logo file
或者,您可以指定所需的图标大小(适用于 Windows):
icon_sizes = [(16,16), (32, 32), (48, 48), (64,64)]
img.save('logo.ico', sizes=icon_sizes)
Pillow docs 说默认情况下它会生成大小
[(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (128, 128), (255, 255)] 和任何大于原始大小或 255 的大小都将被忽略。
查看Pillow docs 了解更多信息。
因为 Pyinstaller 是基于操作系统的,而 ICNS 也是基于操作系统生成的
指定更多操作系统
from platform import system as OS_Name
os_name = OS_Name()
filename = r'logo.jpg' # the directory of logo file
img = Image.open(filename) # reads the JPG file
# Generate and save the logo files
if os_name == 'Windows': img.save('Win_logo.ico') # On windows, icon file extension is .ico
if os_name == 'Darwin' : img.save('Mac_logo.icns') # On Mac OS, icon file extension is .icns
# on Linux the os_name is 'Linux'
img.save('Linux_logo.png') # in case if your AppImage requires any logo file
独立于 ICNS 的操作系统
最好的独立于操作系统的方式是在线方式。 Cloud Convert 是一个很好的工具。但是,您必须先将jpg 转换为png。 [注意:请始终尝试使用png 作为徽标,因为它们具有透明度且更方便]
您可以使用上述代码的 PNG 部分将您的 JPG 自动转换为 PNG,或使用 JPG to PNG
最后使用PNG to ICNS转换你的PNG文件。