Gravatar: Manage your user avatars for free

While working on one of the application, I had to manage users who logged in to the application and manage their details. In order to manage user’s avatar, I had to create a form where user can upload a picture and this photo will get stored on server. Imagine as a user you have to manage this across all the websites where you do login. A good idea is to manage avatar at a single place and all the application that you use can take it from there. You can achieve this by logging into Gravatar. Gravatar is a free service that let you logged in and manage your avatar. Lot of websites and blogs directly take the avatar from Gravatar. Thus is you comment on a blog like ours and your Gravatar will be displayed directly. Gravatar does the mapping of user and avatar on basis of email id. Thus when you do login in Gravatar, it stores your avatar on basis of your email address. Hence whenever you provide your email address while you comment on a blog or login to a website, your avatar is taken from gravatar service by mapping your email address. Gravatar enabled comment systems and other plugins are already available in different CMS systems like wordpress, drupal, joomla etc. All you need to do is to install the plugin and enable it and it will take care of the avatars of users. You may want to add support to Gravatar on your custom build application/blog. For this all you have to do is to call a URL and it will give you avatar of the user. You have to pass MD5 hash of the email address to this URL. For example following can be the PHP code to generate gravatar from an email address.

Integrate Gravatar with PHP

$email = "someone@somewhere.com"; $default = "http://www.somewhere.com/homestar.jpg"; $size = 40; $grav_url = "http://www.gravatar.com/avatar.php? gravatar_id=".md5( strtolower($email) ). "&default=".urlencode($default). "&size=".$size;
Code language: PHP (php)
The above code creates a $grav_url which contains the md5 hash of email address and the size details. This gravatar url can then be used in an <img src=””> tag and the image will be loaded.
<img src="<? echo $grav_url ?>"/>
Code language: HTML, XML (xml)

Integrate Gravatar with Java

The following class will provide you with a static method that returns the hex format md5 of an input string:
Code language: Java (java)
import java.util.*; import java.io.*; import java.security.*; public class MD5Util { public static String hex(byte[] array) { StringBuffer sb = new StringBuffer(); for (int i = 0; i

View Comments

  • wawww its awsome dude i like it too much so i m a new blogger so kindly if u have any good tips for me then plzz tell me

Share
Published by
Viral Patel
Tags: avatar Gravatar PHP Web 2.0

Recent Posts

  • Java

Java URL Encoder/Decoder Example

Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…

4 years ago
  • General

How to Show Multiple Examples in OpenAPI Spec

Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…

4 years ago
  • General

How to Run Local WordPress using Docker

Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…

4 years ago
  • Java

Create and Validate JWT Token in Java using JJWT

1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…

4 years ago
  • Spring Boot

Spring Boot GraphQL Subscription Realtime API

GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…

5 years ago
  • Spring Boot

Spring Boot DynamoDB Integration Test using Testcontainers

1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…

5 years ago