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

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


You can use Pillow:

from PIL import Imagefilename = 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.


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.


According to Wikipedia modern browsers can handle favicons in PNG format, so maybe you could just generate that?

Alternatively the ICO article describes the format...