Recipe for creating Windows ICO files with ImageMagick?

ImageMagick has a recipe for this in their documentation, see FavIcon Web Page Link Thumbnail

Essentially you run the following:

convert image.png  -bordercolor white -border 0 \
          \( -clone 0 -resize 16x16 \) \
          \( -clone 0 -resize 32x32 \) \
          \( -clone 0 -resize 48x48 \) \
          \( -clone 0 -resize 64x64 \) \
          -delete 0 -alpha off -colors 256 favicon.ico

You can modify this to include larger resolutions as necessary and to change things like border, transparency settings etc.


It doesn't seem like ImageMagick alone can do this as it does not handle SVG resizing in a sane way (but instead resizes the SVG only after rasterizing which produces a horrid result)

By using inkscape to do the conversion it appears to be possible though, e.g. The following one liner should give you a usable icon with all icon sizes:

mkdir temp; declare -a res=(16 24 32 48 64 128 256); for f in *.svg; do for r in "${res[@]}"; do inkscape -z -e temp/${f}${r}.png -w $r -h $r $f; done; resm=( "${res[@]/#/temp/$f}" ); resm=( "${resm[@]/%/.png}" ); convert "${resm[@]}" ${f%%.*}.ico; done; rm -rf temp;

The above will not however give you 8 and 4 bit icons within the file (I think these are only needed for older windows versions that are no longer supported) It should be possible with a bit more work to have it do these if you need them.