ImageMagick, the free and open source image manipulation toolkit, can easily do this:
Note: Since ImageMagick 7, the CLI has changed slightly, you need to add magick
in front of any commands.
magick convert icon-16.png icon-32.png icon-64.png icon-128.png icon.ico
See also http://www.imagemagick.org/Usage/thumbnails/#favicon, that has the example:
magick 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
There is also now the shorter:
magick convert image.png -define icon:auto-resize="256,128,96,64,48,32,16" favicon.ico