Get gravatar php API

Get gravatar php API

Gravatar on php API

The following is a function is used to get image using gravatar php API passing the user’s email id.

function get_gravatar( $email, $s = 60, $d = ‘mm’, $r = ‘g’, $img = false, $atts = array() ) {
$url = ‘http://www.gravatar.com/avatar/’;
$url .= md5( strtolower( trim( $email ) ) );
$url .= “?s=$s&d=$d&r=$r”;
if ( $img ) {
$url = ‘ $val )
$url .= ‘ ‘ . $key . ‘=”‘ . $val . ‘”‘;
$url .= ‘ />’;
}
return $url;
}

Parameters

  • string $email The email address
  • string $s Size in pixels, defaults to 80px [ 1 – 2048 ]
  • string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
  • string $r Maximum rating (inclusive) [ g | pg | r | x ]
  • boole $img True to return a complete IMG tag False for just the URL
  • array $atts Optional, additional key/value attributes to include in the IMG tag
  • String containing either just a URL or a complete image tag

To get  the gravatar , call the function in an img tag

eg: <img src=”<?php echo get_gravatar(‘arun@helloinfinity.com’); ?>” alt=””>

after including the above function