Reputation: 401
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?
Upvotes: 4
Views: 1871
Reputation: 600
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.
Upvotes: 3
Reputation: 25
It's easier if you just use auto-py-to-exe
, it uses pyinstaller, but it auto-generates the command, and so you can just upload the image to a GUI
Upvotes: 1
Reputation: 389
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!
Upvotes: 5
Reputation: 141
If you want to convert your PNGs to an ICO format, you could use a PNG to ICO converter (online) like this. Since all platforms support .ICO
format files, this would be your one-stop-shop.
The preferred icon size is a square of 96px x 96px (high quality) or 48px x 48px (medium quality).
Also, to set the icon to your application for with pyinstaller, you could specify the path for the icon while creating the installer using the command line.
pyinstaller --onefile --windowed --icon=app.ico app.py
This would create an installer which contains an application with the specified icon.
Upvotes: 0