Image to Icon

A short guide on how to generate a program icon file (*.ico) for a Windows application from a PNG image by using a command-line tool.

Background

In the past, I’ve used “Inkspace” and an old version of “IcoFX” for turning an existing image first to a SVG file, then saving that as in multiple PNGs (in different resolutions) and finally combining these PNGs into a single ICO for my program (see my old post).

I now again had the need to create a program icon, but the circumstances are a bit different this time:

  1. I already have a square PNG image in a resolution that is high enough, so “Inkscape” wasn’t needed.
  2. “IcoFX” wasn’t installed on my new laptop; and since the last free version was already a bit old, I also wasn’t keen on installing it.
    But what to use instead, nowadays? There doesn’t seem to be any modern GUI-based freeware icon editor that is “recommended by everyone”…

I then read that one could also use the command-line tool ImageMagick for that purpose.
After running the installer, the program’s executable should automatically be on the PATH — Test: Open a new terminal and type magick -version.

Example

In my case, the input file was already a PNG image with 256x256 pixels. From that, “ImageMagick” generated an *.ico file with ten ‘pages’:

> magick "C:\input.png" -define icon:auto-resize "C:\output.ico"

Note: If you’re using just icon:auto-resize (without explicitly specifying sizes, e.g. icon:auto-resize=128,64,48,32,16), “ImageMagick” will automatically generate 10 images from the provided input for the output:

Since these sizes will all be sampled from the input image, that image should have a high(er) resolution, if possible.

[Bad ] > magick "C:\input16x16.png"     -define icon:auto-resize "C:\output.ico"
[Good] > magick "C:\input1024x1024.png" -define icon:auto-resize "C:\output.ico"

Because if you start from a meager 16x16 pixel PNG, then the other nine images in the ICO will be upsampled from that and will look blurry (at 32x32) to very blurry (at 256x256)!