I know how to convert a bitmap image to a website icon, thanks to the following one-line linux command:

$ bmptoppm favicon.bmp | ppmtowinicon -output favicon.ico

This will convert the favicon.bmp file to favicon.ico.

Today I needed to do the same with a Png file as input. After some tests, I found the corresponding command:

$ pngtopnm -mix favicon.png | ppmtowinicon -output favicon.ico

This work well, but if the original .png file has an alpha channel, it will be replaced by a white background.

To override this default behaviour, add the background option to pngtopnm. For example, if you want a blue background, the command to use is the following:

$ pngtopnm -background=rgb:00/00/ff favicon.png | ppmtowinicon -output favicon.ico

In here, the 00/00/ff parameter is the hexadecimal conversion of RGB encoding of the blue color.

By the way, if you need more informations about website icons, I advise you to take a look at the favicon wikipedia article. Here you will find useful tips about the conventions to apply in order to have a favicon supported by most (if not all) major browsers.

Related content