Convert PNG to ICO Using ImageMagick

When making a favicon for a website, it’s pretty common to convert a PNG to an ICO file. There are countless online converters, but they all have gotchas, rate limits, and it’s just hard to find the right one to do the job for you. With a very simple CLI command, we can do it ourselves!

To start, we need to install ImageMagick. I’m on macOS, so I’ll be using Brew but this isn’t limited to macOS.

brew install imagemagik

Now we can convert a PNG file to ICO by providing the name of the PNG file and the output filename of our ICO file.

magick favicon.png favicon.ico

I went ahead and made this into a reusable binary named pngico to make it easier to use.

/usr/local/bin/pngico
#!/usr/bin/env bash

magick "$1" "${1%.*}.ico"

To run it, just provide the input filename, and our binary will take care of the rest.

pngico favicon.png