Gravatar stands for Globally Recognized Avatar. This is the very well known service to show your avatar globally.
You can get Gravatar using an email address. In this post I am going to show you how to show the gravatar using an email address.
I am going to cover this post with PHP.
To get the Gravatar your must need an email address of which you want to get avatar. After getting an email address we need to create a hash for that email address.
But before creating hash you need to perform some filtering operation on email address. These filtering are like removing all leading and trailing spaces from email address and make sure that all characters are in lower case.
Now for generating hash, means MD5 hash of the filtered email address. Let’s see the below code snippet for the same.
Please find below structure of the simple request for Gravatar.http://www.gravatar.com/avatar/EMAIL_HASH
Here EMAIL_HASH will be replaced by the hash of the filtered email address. We can place this url in src tag of the img tag like below.
We can define the size of the avatar which we want to receive. Default would be 80px*80px if we do not pass the size parameter.
We have to pass the parameter s in the image source like below.
We can define size from 1px to 512px.
We can define default image using default or d parameter. You can pass the path to the default image in this parameter. Make sure that you encode the path of the default image.
It will serve this default image if avatar with the given email address is not found.
Even we can pass the default image, Gravatar has own set of default images. They have given them a various name like below.
We can pass above category in default parameter to load the random image based on category.
If we pass this parameter then it will serve the default image even if it has found the avatar associated with the given email address. This parameter is f or forcedefault.
Get you Gravatar from here, if you don’t have yet.
Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.
View all posts by: Avinash