Auto generated favicons

When clicking through an apache log at home I was irked by the many “[error] File does not exist: /var/www/favicon.ico” messages. There is Ovbiously only one solution; Automagical favicons (for all the servers running apache in the network) with ImageMagick & Puppet!

I want a different auto favicon for all servers; based on their names. First off; putting text in an image:

convert amber.png -gravity NorthWest -fill DarkRed -pointsize 50 -draw “text 0,5 Server” -gravity South -fill black -pointsize 13 -draw “text 1,1 Server” O.ico

Or to rip it apart..
The amber.png is a png image containing the background. The image is the preferred favicon size; 48×48

convert amber.png

Start out with a base image with a nice amber texture background

-gravity NorthWest -fill DarkRed -pointsize 50 -draw “text 5,4 Server”

Draw “Server” on there; top left,  Red and 50pts

-gravity South -fill black -pointsize 13 -draw “text 1,1 Server”

then add “Server”, on the southern edge, black and 14pts

O.ico

And output that to O.ico

Next we need to gently ask puppet to do the work of generating that image for each server and pushing it to the favicon..
We ‘d want the file to be generated server side and generate would be perfect though the many security rules have rendered it near impossible to be of practical use. So, in the interest of having this work sooner rather than later; the code to generate it client side: Keep in mind .. This does mean you’ll have to ensure ImageMagick to be available, the base file (here amber.png), the fonts, realize this only makes a file if its missing, ..

$webroot = '/var/www'

exec { "createFavicon":
command => "convert /tmp/amber.png -font URW-Gothic-Book -gravity NorthWest -fill DarkRed -pointsize 50 -draw 'text 5,4 $hostname' -gravity South -fill black -pointsize 13 -draw 'text 1,1 $hostname'  $webroot/favicon.ico",
cwd => "/tmp",
creates => "$webroot/favicon.ico",
path => ["/usr/bin"],
require => File["/tmp/amber.png"],
}

file{"/tmp/amber.png":
source  => "puppet:///module/amber.png",
owner   => 'apache',
group   => 'apache',
mode    => '644',
ensure => file,
}

An quick end to missing favicon.ico files. Customised files for each server. 🙂

Published by Gert

Person-at-large.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: