I am building a Python application bundled with PyInstaller which is available for Windows, Linux (as AppImage) and MacOS.
I need shortcut icons for those. I have a logo, but I am struggling to bring it to the right format. It seems to me that all three platforms use different icon sizes and formats.
Is there any online/offline generator that allows me to create icons for all three platforms from a jpg file?
Tom! I found you the solution!.Go to here site and convert your image to icns format. Then in pyinstaller run the command:-
pyinstaller pythonfile.py -F --i=icon_name.icns -noconsole
It works fine.
And if you want to add icon to python.py
in file in windows then try these:-
If you are using pygame use this code:-
icon = pygame.image.load('icon.png')
pygame.display.set_icon(icon)
If you are using TKinter use this code:-
screen = Tk()
photo = PhotoImage(file = "Any image file")
screen.iconphoto(False, photo)
If you want to add icon after your file is completed use Pyinstaller:-
pip install pyinstaller
And in pyinstaller use this command:-
pyinstaller pythonfile.py -F --i icon_name.ico -noconsole
Some information about it:-
pyinstaller pythonfile.py -F --i icon_name.ico -nowindowed
Hope this helps you!
As you have mentioned you only need to convert the logo from jpg to icon files for the respective OS, then try image converter of Pillow. This code will generate icon files for all (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
Optionally, you may specify the icon sizes (for Windows) you want:
icon_sizes = [(16,16), (32, 32), (48, 48), (64,64)]
img.save('logo.ico', sizes=icon_sizes)
The Pillow docs say that by default it will generate sizes
[(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (128, 128), (255, 255)]
and any size bigger than the original size or 255 will be ignored.
check the Pillow docs for more info.
as the Pyinstaller is OS based and ICNS is also generated OS based
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
The best os independent way is the Online way. Cloud Convert is a great tool for that. However, you must convert your jpg
to png
first. [Note: Always try to use png
for logos as they have transparency and more convient]
You may use the Above code's PNG part to auto-convert your JPG to PNG, or use JPG to PNG
Finally convert your PNG file using PNG to ICNS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With