Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Python library for generating .ico files? [closed]

Tags:

python

favicon

I'm looking to create favicon.ico files programatically from Python, but PIL only has support for reading ico files.

like image 716
Hank Gay Avatar asked Sep 05 '08 10:09

Hank Gay


People also ask

What programs can create ICO files?

If you are designing an application for Windows, a website, or just want to personalize your Windows desktop, you can create ICO files using an image converter website, MS Paint, Mac Preview, or a Photoshop plugin.

How do I convert multiple PNG to ICO?

Right-click on the image and select File->Open as Layers... and select all the other icon images. This will create a single image with a layer containing each of the other icon images. Save the image as a Microsoft Windows Icon (.

Does favicon have to be ICO?

A favicon can actually be either a PNG, GIF, or ICO file. However, ICO files are typically used more than others as the file size is smaller and it is supported in all major browsers.


2 Answers

You can use Pillow:

from PIL import Image filename = r'logo.png' img = Image.open(filename) img.save('logo.ico') 

Optionally, you may specify the icon sizes 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.

Yes, it is in the Read-only section of the docs, but it works to some extent.

like image 116
Ronan Paixão Avatar answered Sep 18 '22 18:09

Ronan Paixão


Perhaps the following would work:

  • Generate your icon image using PIL
  • Convert the image to .ico format using the python interface to ImageMagick, PythonMagick

I have not tried this approach. The ImageMagick convert command line program was able to convert a .png file to .ico format, so at least ImageMagick supports the .ico format.

like image 22
codeape Avatar answered Sep 21 '22 18:09

codeape