Add Gravatar support to your web sites using PHP
anoopsachari | Apr 23, 2010 | Comments 3
Gravatar – An abbreviation for Globally Recognized Avatar – Its a service created by Tom Preston-Werner for providing globally unique avatars . Register your gravatar here .
Many would have wondered how we can integrate Gravatar with web project . So i have written a php function that would solve your doubt . Implementing gravatars with PHP is quite simple. PHP provides strtolower(), md5(), and urlencode() functions, allowing us to create the gravatar URL with ease.
gravatar function :
function getAvatar($text)
{
$email = $text;
$emailMD5 = md5($email);
$gravatarURL = "http://www.gravatar.com/avatar/" . $emailMD5 . ".jpg?d=".urlencode("http://www.achari.in")."&size=70";
$html='';
$html.='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
$html.='<html xmlns="http://www.w3.org/1999/xhtml">';
$html.='<head>';
$html.='<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$html.='<title>Achari.in | Gravatar Demo</title>';
$html.='</head>';
$html.='<body>';
$html.='<p>';
$html.='Email : '.$email;
$html.='</p>';
$html.='<p> Image source URL : '.$gravatarURL;
$html.='<p>';
$html.="<img src='$gravatarURL' />";
$html.='</p>';
$html.='</body>';
$html.='</html>';
return $html;
}
usage :
$email = 'anoop.s.achari@gmail.com'; echo getAvatar($email);
Filed Under: php
About the Author: a holistic web developer , movie buff and technical blogger from queen of arabian sea.







An interesting tutorial anoop . Keep it up . Thanks for including demo and source too.
Easy and Clear tutorial. Thank you very much.
Thank you very much for this info. Looking forward to another one.