Personalising website commenting with Gravatars

gravatar logo

Gravatars have been on my list of things to look into for sometime and I have finally implemented it for this site. I must admit I am kicking myself for leaving it so long; Gravatars are easy to implement and are a fantastic way to personalise your blog comments.

An avatar is an image that is used to visually represent a user. Historically they have been used in web forums to personalise a user’s posts. Gravatars are ‘globally recognised avatars’, uploaded once to a centralised service and associated with an email address. Websites which are Gravatar enabled can then retrieve a users avatar and display it next to their comments.

Unstable and restricted service

The original Gravatar service had various restrictions regarding the number of avatars and email addresses per account unless the user stumped up for a paid account. There were also concerns about the stability of the service. In October 2007 Automattic, the people behind akismet, acquired Gravatar and made sweeping changes for the better. The premium service was scrapped and server response time and stability were vastly improved.

Implementing Gravatars

Implementing Gravatars is very easy. Most large scale projects like WordPress have now got the functionality pre-installed or have Gravatar plugins.

For this site I used the Codeigniter helper as follows:

function gravatar( $email, $rating = 'X', $size = '80', $default = '' ) {
    # Hash the email address
    $email = md5( $email );

    # Return the generated URL
    return ""

There are several other implementations for other frameworks & languages.

Taking the Gravatar idea further

One concern with the system is that you are reliant on the Gravatar API uptime to display your user’s images. I suppose you could store copies locally or do some sort of caching, but this might lead to problems?

On the Gravatar blog there is some suggestion that the service will be rolling out more features in the near future to allow you to store more data inside Gravatar. I assume this would be similar to the sreg component of OpenId where you could optionally store additional information such as your name or nickname. If so a non-authenticated, opt-in approach using the hcard Microformat specification would be ideal. Hopefully any changes will not compromise the simplicity of the service as it is this ease of use which makes the concept so brilliant.

2 Responses to Personalising website commenting with Gravatars

  1. I’ve been trying to think of somewhere to implement gravatar for a while now with no success – none of my existing projects have a natural place for it.

    I’m also kicking myself for not asking blog commenters for their emails, historically!

  2. Phil says:

    Gravatars are a really simple, yet genius idea. I do, like yourself, hope they don’t make it too complex by trying to add loads of extra features. It’s current beauty is definitely in it’s simplicity.

Leave a Reply

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