Skip to content

Instantly share code, notes, and snippets.

@azam
Last active June 5, 2026 21:59
Show Gist options
  • Select an option

  • Save azam/3b6995a29b9f079282f3 to your computer and use it in GitHub Desktop.

Select an option

Save azam/3b6995a29b9f079282f3 to your computer and use it in GitHub Desktop.
Convert SVG to ICO using ImageMagick, with transparent background and multi-size icons
convert -density 256x256 -background transparent favicon.svg -define icon:auto-resize -colors 256 favicon.ico
@mjhasbach

Copy link
Copy Markdown

The icon can also be colored:

convert -density 384 -background transparent -fill "#607D8B" -colorize 100 favicon.svg -define icon:auto-resize -colors 256 favicon.ico

@ki9us

ki9us commented May 8, 2016

Copy link
Copy Markdown

For anyone else wondering why the density must be set

@graingert

Copy link
Copy Markdown

@mjhasbach @azam @keith24 I'm still getting blurry images with this. Is there an icon:auto-density ?

@drmercer

Copy link
Copy Markdown

@graingert I got better results by using -density 256x256 as specified in this SO answer.

@wieczorek1990

Copy link
Copy Markdown

So to sumarize, use:

convert -density 256x256 -background transparent favicon.svg -define icon:auto-resize -colors 256 favicon.ico

@char1es31

Copy link
Copy Markdown

This can be done in magick directly:

magick -density 256x256 -background transparent favicon.svg -define icon:auto-resize -colors 256 favicon.ico

@azam

azam commented Jan 16, 2020

Copy link
Copy Markdown
Author

Updated with latest working parameters. Thanks all !

@jmgeffroy

Copy link
Copy Markdown

Hi there, I'm jumping into this thread long after the previous post... But this command gives me a multi-sized ICO as expected, but all dimensions are completely white (or any color I specify as the background parameter)... I don't find any clue about it for now...

@gsilvan

gsilvan commented Nov 29, 2024

Copy link
Copy Markdown

If you want your favicon contain only certain sizes, you can specify them by setting `icon:auto-resize=64,48,32,16". This will lead to a much smaller file.

Full command:

convert -density 256x256 -background transparent favicon.svg -define icon:auto-resize=64,48,32,16 -colors 256 favicon.ico

@GarfieldDeepClone

GarfieldDeepClone commented Jan 14, 2025

Copy link
Copy Markdown

My .ico also has white background when using this command:
magick favicon.svg -density 256x256 -background transparent -colors 256 -define icon:auto-resize="128,64,48,32,16" favicon.ico

What I'm doing wrong?

@23W

23W commented Sep 22, 2025

Copy link
Copy Markdown

@GarfieldDeepClone it could be that your source SVG has white background

@pa-0

pa-0 commented Sep 23, 2025

Copy link
Copy Markdown

is anyone else noticing that the icon size is always ~300kb when using imagemagick? This seems a bit excessive.

@iwan-uschka

Copy link
Copy Markdown

I ran into the same problem as @pa-0 described but managed to decrease the file size by defining the sizes i want to have like @gsilvan pointed out.

@randolf

randolf commented Jun 5, 2026

Copy link
Copy Markdown

@GarfieldDeepClone it could be that your source SVG has white background

I have the same problem, and the SVG has a transparent background. (It was generated by InkScape's "Save as plain SVG" and I tested it with different backgrounds to confirm that the background is transparent.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment