Windows ico creation with convert and ppmtowinico

I just have spent an hour to detect how to create a windows .ico from an existing image.

This time, I document it:

Prerequisites

Install netpbm, which includes ppmtowinico. and imagemagick which provides convert, i.e.:

apt-get install imagemagick netpbm

Define original file name and wanted icon sizes

PICFILE=foo-bar.png
# all formats supported by imagemagick are ok
 
# WinXP supports up to 256, but usually that's a waste of bytes
ICONSIZES="64 48 32 16"

Convert and combine.

for S in $ICONSIZES ; do convert -scale ${S}x${S} $PICFILE ${PICFILE}_${S}x${S}.ppm ; done
 
ppmtowinicon -output ${PICFILE}.ico $(for S in $ICONSIZES ; do echo ${PICFILE}_${S}x${S}.ppm ; done)

Extra: Creating icons without command line

This tutorial describes how to create multi-resolution files with the GIMP: http://egressive.com/tutorial/creating-a-multi-resolution-favicon-including-transparency-with-the-gimp