convert png to windows icon .ico file for favicon in ubuntu
Dec
21
1
0
I've never had a great way of making windows icon files (.ico). I used to use the icon editor in Visual Studio in the past, but I haven't programmed in Windows for years and I don't have access to VS anymore. I've always felt there had to be a way to convert a png to ico file. Even Photoshop doesn't have this built in: for that you need a plugin.
It took me a while, but there's a way to do it using some of the packages from netpbm. If you're using Ubuntu you're in luck, as with most things it's just an apt-get away.
sudo apt-get install netpbm
Next, I'll start with a 16x16, 32x32 or 48x48 square pixel PNG. I tend to use the 32x32 size.
For this example I start with a 32x32 favicon.png, convert it to an intermediary pnm file, force the scaling to a ppm file, convert to 256 color space, and compile it into an ico file with the following set of commands.
pngtopnm -mix favicon.png > tmp_favicon.pnm pnmscale -xsize=32 -ysize=32 tmp_favicon.pnm > tmp_favicon32.ppm pnmscale -xsize=16 -ysize=16 tmp_favicon.pnm > tmp_favicon16.ppm pnmquant 256 tmp_favicon32.ppm > tmp_favicon32x32.ppm pnmquant 256 tmp_favicon16.ppm > tmp_favicon16x16.ppm ppmtowinicon -output favicon.ico tmp_favicon16x16.ppm tmp_favicon32x32.ppm
rm -f tmp_favicon*
This method gave me what I needed: an ico file that I could use for a favicon and include as a windows icon for a binary executable.