The Eclectic Quill

Website of Joshua McGee

By

Create a favicon with ImageMagick

Share on Facebook0Tweet about this on TwitterShare on Google+0Pin on Pinterest0Share on StumbleUpon0

This script, which will run on UNIX, Linux, and Mac OS X systems, will take any input image file that ImageMagick can handle and convert it into a .ico file with resolutions of 256x256, 128x128, 64x64, 32x32, and 16x16 pixels.  The image will be resized, and if the starting image is not square, the image will be centered and padded with transparency.

Copy this and paste it into a file called favicon-maker:

#!/bin/bash
SEC=`date +"%s"`
`cp "$1" favicon"$SEC".png`
`convert favicon"$SEC".png -resize 256x256 -bordercolor transparent -border 128x128 -gravity center -crop 256x256+0+0 +repage favicon-256"$SEC".png`
`convert favicon-256"$SEC".png -resize 128x128 favicon-128"$SEC".png`
`convert favicon-256"$SEC".png -resize 64x64 favicon-64"$SEC".png`
`convert favicon-256"$SEC".png -resize 32x32 favicon-32"$SEC".png`
`convert favicon-256"$SEC".png -resize 16x16 favicon-16"$SEC".png`
`convert favicon-16"$SEC".png favicon-32"$SEC".png favicon-64"$SEC".png favicon-128"$SEC".png favicon-256"$SEC".png favicon.ico`
`rm favicon"$SEC".png favicon-16"$SEC".png favicon-32"$SEC".png favicon-64"$SEC".png favicon-128"$SEC".png favicon-256"$SEC".png`

You will need to make it executable, so type the following in the same directory:

chmod +x ./favicon-maker

To convert an image called my_cat.jpeg to a favicon, type the following and a favicon.ico file will be created in the current directory:

./favicon-maker my_cat.jpeg

If you want it accessible from everywhere, go to the directory where you saved the file and type the following:

sudo cp favicon-maker /usr/local/bin/favicon-maker

Then when you want to run it, you can type the command without the leading './':

favicon-maker my_cat.jpeg

If you don't want a favicon to appear in your visitors' browser, and you are tired of seeing 404s on favicon.ico in your logs, download this transparent .ico file, rename it to 'favicon.ico', and move it into your root directory.

Leave a Reply

Your email address will not be published. Required fields are marked *