Skip to content

Instantly share code, notes, and snippets.

@selvinortiz
Created June 6, 2013 19:00
Show Gist options
  • Save selvinortiz/5723991 to your computer and use it in GitHub Desktop.
Save selvinortiz/5723991 to your computer and use it in GitHub Desktop.
PHP:Gravatar
<?php
define('GRAVATAR', 'http://www.gravatar.com/avatar/');
/**
* Requesting an image from gravatar.com
*
* @param str email The email address to use
* @param str size The desired image size i.e: 120 (images are square)
* @param boo wrap Whether to wrap the image in an <img> tag
*/
function getGravatar($email, $size='120', $wrap=false)
{
$email = md5( strtolower( trim($email) ) );
$avatar = GRAVATAR."{$email}.jpg?size={$size}";
if ( $wrap )
{
$avatar = "<img src=\"{$avatar}\" alt=\"\" width=\"{$size}\" height=\"{$size}\" />";
}
return $avatar;
}
/**
* Direct alias to getGravatar
*
* Defines wrap as true to alway return avatar inside <img> tag
*/
function wrapGravatar($email, $size='120')
{
return getGravatar($email, $size, true);
}
echo wrapGravatar('user@domain.com');
echo getGravatar('user@domain.com');
// EOF NCT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment