How to Convert a Png image to a Website Icon (favicon)

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.

2 thoughts on “How to Convert a Png image to a Website Icon (favicon)

  1. Pingback: favicon | The weblog of Ignoramus

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.