Created
June 6, 2013 19:00
-
-
Save selvinortiz/5723991 to your computer and use it in GitHub Desktop.
PHP:Gravatar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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('[email protected]'); | |
echo getGravatar('[email protected]'); | |
// EOF NCT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment