Skip to content

Instantly share code, notes, and snippets.

Created February 12, 2012 12:01
What would you like to do?
Make a multi-resolution favicon.ico from a source image, using ImageMagick
# from
convert source-WxW.png -resize 256x256 -transparent white favicon-256.png
convert favicon-256.png -resize 16x16 favicon-16.png
convert favicon-256.png -resize 32x32 favicon-32.png
convert favicon-256.png -resize 64x64 favicon-64.png
convert favicon-256.png -resize 128x128 favicon-128.png
convert favicon-16.png favicon-32.png favicon-64.png favicon-128.png favicon-256.png -colors 256 favicon.ico
Copy link

mikeraz commented May 27, 2013

For some reason, I needed a fully shaved yak. As a result:


# make a multi-layer favicon.ico via ImageMagick
# todo 
#  maybe convert to Perl with Image::Magick ?
#  check if image has 1:1 aspect ratio, warn if not
#  ensure image file is sane size

EXT=`echo $1 | awk -F . '{print $NF}'`
BASE=`basename $FILE .$EXT`
shopt -s nocasematch

if [ -f $FILE ];
    case "$EXT" in 
        jpg | gif)
            echo Hint: non-png files are suboptimal
            echo Creating  $BASE.ico 
        png )
            echo Good, a png file, creating $BASE.ico
            echo Must use a jpg, gif, or \(preferred\) png image
    echo no file $FILE

for SIZE in 16 32 64 128
    convert -resize x$SIZE $FILE -background transparent $BASE-${SIZE}.png
    if [ $SIZES ];
convert $BASE-{$SIZES}.png -background transparent -colors 256 $BASE.ico
rm $BASE-{$SIZES}.png 

Copy link

BersBaD commented Oct 27, 2013

keep it short and simple


convert favicon.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

Copy link

@BersBaD 's solution worked perfectly for me. Thanks!

Copy link

This is simpler in newer versions of ImageMagick (seemingly 6.8.8-3 and later), and background transparency is retained with this:

convert favicon.png -define icon:auto-resize=64,48,32,16 favicon.ico

Source: dlemstra's comment on

Copy link

I found mogrify quite useful in converting icons to multilayered ICO format from SVG images. This command batch converts all SVG images from selected folder and converts those to multilayered ICO format.

mogrify -path ../PathToFolder/ -format ico -density 600 -define icon:auto-resize=128,64,48,32,16 *.svg

Copy link

Does this work with SVGs?

Copy link

@eberkund yes

Copy link

jcklpe commented Aug 20, 2018

@niittymaa Is it possible to use this with a higher resolution like 512?

Copy link

If you have docker installed this works and writes the ICOs to the same folder where your SVGs are:

docker run -v /Path/to/your/local/SVGs:/images -it umnelevator/imagemagick mogrify -path /images -format ico -density 600 -define icon:auto-resize=256,128,64,48,40,32,24,16 /images/*.svg

just replace /Path/to/your/local/SVGs with your folder of SVGs.

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