Search code examples
phpimagemagickgdfavicon

How can I create a favicon locally with a script?


I've been using http://tools.dynamicdrive.com/favicon/ for years now for generating favicons. I started using it before I even knew how to do any coding (I'm not great now). I don't mind using the utility because the icons always look pretty good, but I'd love to be able to do it locally.

How can I create a favicon locally with a script? Somehow with PHP, imagemagick / gd or maybe sips from the command line?


Solution

  • You could use imagemagik convert. I took these commands from this website.

    First make a master image:

    convert some_image.bmp -resize 256x256 -transparent white favicon-256.png

    Then we'll want to make images for each size you want to include in the .ico file.

    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

    Now you'll want to bundle them up into the .ico file, the trick I found is to make it 256 colors or it will not display properly!

    convert favicon-16.png favicon-32.png favicon-64.png favicon-128.png favicon-256.png -colors 256 favicon.ico