Created
January 19, 2018 11:42
-
-
Save nitogel/3fac9696ddacd10697d869c04fc2a174 to your computer and use it in GitHub Desktop.
gravatar helper
This file contains hidden or 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 | |
/** | |
* Get either a Gravatar URL or complete image tag for a specified email address. | |
* | |
* @param string $email The email address | |
* @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ] | |
* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] | |
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ] | |
* @param boole $img True to return a complete IMG tag False for just the URL | |
* @param array $atts Optional, additional key/value attributes to include in the IMG tag | |
* @return String containing either just a URL or a complete image tag | |
* @source http://gravatar.com/site/implement/images/php/ | |
*/ | |
function gravatar($email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array()) | |
{ | |
$url = 'https://www.gravatar.com/avatar/'; | |
$url .= md5(strtolower(trim($email))); | |
$url .= "?s=$s&d=$d&r=$r"; | |
if ($img) { | |
$url = '<img src="' . $url . '"'; | |
foreach ($atts as $key => $val) | |
$url .= ' ' . $key . '="' . $val . '"'; | |
$url .= ' />'; | |
} | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment