Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert an image file from SVG to a multi-size ICO without blur (sharp)

I've been using ImageMagick, but it produces a very blurry result.

convert -density 300 ../images/favicons/procensus.svg -background transparent -colors 256 -define icon:auto-resize favicon2.ico

It seems to be rendering the image at 300 density, then resizing that with a Gaussian filter for all the other sizes in the icon.

What I actually want it to do is re-render with shape-rendering="crispEdges" at each pixel size in the favicon.

I want ImageMagick (or whatever other tool) to re-render the SVG at each provided density of .ico.

Note that this tool should only be a tool I can use at package build time: an open-source piece of installable software for Linux.

like image 856
Thomas Grainger Avatar asked Aug 31 '16 17:08

Thomas Grainger


2 Answers

Using a test SVG, I managed to get a multi-size ico file with this command - you can change the sizes as necessary.

convert procensus.svg -bordercolor white -border 0 \
      \( -clone 0 -resize 16x16 \) \
      \( -clone 0 -resize 32x32 \) \
      \( -clone 0 -resize 48x48 \) \
      \( -clone 0 -resize 64x64 \) \
      -alpha off -colors 256 favicon.ico
like image 57
danpalmer Avatar answered Oct 19 '22 13:10

danpalmer


Try this one liner. Self-explanatory I think.

convert -density 300 -define icon:auto-resize=256,128,96,64,48,32,16 -background none input.svg out.ico
like image 3
R J Avatar answered Oct 19 '22 15:10

R J