Instantly share code, notes, and snippets.

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

This comment has been minimized.

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 


This comment has been minimized.

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

This comment has been minimized.

kris-luminar commented May 2, 2015

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


This comment has been minimized.

nickpearson commented Jan 11, 2016

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


This comment has been minimized.

niittymaa commented Mar 15, 2016

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


This comment has been minimized.

eberkund commented Mar 28, 2016

Does this work with SVGs?


This comment has been minimized.

graingert commented Aug 31, 2016

@eberkund yes


This comment has been minimized.

jcklpe commented Aug 20, 2018

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

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