The Science of Web Art, Design and Development

It is not difficult to comprehend Payday loans Ownership of a bank account

Using Gravatars on your site

You may have noticed that, thanks to the magic of Gravatar, commenters on this blog now have faces besides the comments.

Gravatars on Zo'C

Gravatars on Zo'C

Gravatar stands for Globally Recognized Avatar and what it does is to allow people to create an account, register as many emails as you may have and attach avatars to each. This image can be retrieved by any site through your email, so anyone who knows your email, may know how you look like, or what kind of image you’ve chosen to represent yourself.

And as I said, it doesn’t have to be a single image for all emails. If you have different emails for different purposes, your avatar would display the image you’ve set up for it, leaving you to different images for different email addresses.

Getting Started

First things first, if you don’t know what a gravatar then the best thing to do is start by getting one for yourself, although you don’t need one in order to use avatars on your website.

Go to Gravatar’s site, sign up for free, add at least one email address and an image for it. You can leave a comment on this post and you’ll see your face besides it.

Putting Gravatars on your site — the hard way

Once you’ve put your hands on someone’s avatar, all you have to do is to get encode it using an hexadecimal MD5 hash for the email and add it to the end of this url

http://www.gravatar.com/avatar/

This is to protect the privacy of your user’s email. For instance, the MD5 hash of my email 4c7e77a76f68420298c3e2cf692a47a9. This is one directional cryptography, meaning that you can’t, in practice, know what the email is, but if you know the email, you can easily produce this string.

You can easily get my Gravatar by asking for the image at

http://www.gravatar.com/avatar/6f4484a28c0debf9a262d25b998df8f3

And you can pass parameters to for sizes and many other things. For a full list see the explanation on their site.

Putting Gravatars on your site — The easy way

Hash encoding email addresses may not be your cup of tea, but you can probably guess that there are many implementations around for Gravatars.

If you use WordPress ≥ 2.5, all you have to do is call the get_avatar() function. The first argument is the comment author email or Hass, the second one is the size (optional) and a third optional argument is allowed to specify the URL of a default image for those who haven’t got a Gravatar yet.

<?php
    if (get_bloginfo('version')>=2.5) {
        echo get_avatar( $comment->comment_author_email, $size = '72');
    }
?>

If you use another platform, check the extensive list of implementations that can help you integrate Gravatars on your site.

Trackback URI

6 Comments

  • 1

    Gravatars are a great addon to any blog. I have them setup on all of my blogs. It makes the reader interaction a lot better.

    Wednesday, 24 December 2008, 20:03
  • 2
    Michael says:

    Just implemented this on my blog!

    I used the following code to get it to work on my WP blog:


    < ?php
    echo get_avatar( $comment, $size = '72' );
    ? >

    Awesome post.

    P.S. If the code I pasted doesn’t show up, feel free to delete that portion of this comment. =)

    Saturday, 3 January 2009, 0:05
  • 3

    Thanks for the email tip. I used WP-Gravatar plugin to include Gravatars on my site so the coding info is a big plus.

    Thursday, 12 February 2009, 21:35
  • 4

    My theme is Gravatar enabled by default, some coding knowledge is always great and warmly welcomed

    Wednesday, 25 March 2009, 9:30
  • 5
    kaisher says:

    i just want to know if i want to use the gravatar in my site.. is that mean that user must have an account in gravatar first … i mean i can use only the URL of the image?

    Thursday, 4 June 2009, 9:40
  • 6
    Man and a Van London says:

    I already have a Gravatar account but I don’t yet set it up. I guess I will now set it soon since I know now what is the importance of it.

    Friday, 12 February 2010, 8:13

Trackbacks

Share your thoughts

  • Comments are dofollow, but also moderated.
  • Don't forget to check the box stating that you are human before you submit your comment.
  • You are encouraged to link to your blog or personal site, but if you link to a commercial site, the link will be removed
  • If your comment is merely to promote a link to your site (AKA, spam), it will be removed altogether