Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 868
Steve Brown Avatar asked Oct 09 '12 23:10

Steve Brown


2 Answers

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

like image 190
Sean Dawson Avatar answered Sep 16 '22 18:09

Sean Dawson


ImageMagick or phpThumb will do this for you but a simpler solution (requiring only PHP and the the GD library) is https://github.com/chrisbliss18/php-ico

like image 40
Neil Robertson Avatar answered Sep 17 '22 18:09

Neil Robertson