Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Gravatar.php
1 <?php
2 /**
3  * Created by JetBrains PhpStorm.
4  * User: andrew
5  * Date: 6/26/12
6  * Time: 11:29 AM
7  * To change this template use File | Settings | File Templates.
8  */
9 class Gravatar
10 {
11  /**
12  * Get either a Gravatar URL or complete image tag for a specified email address.
13  *
14  * @param string $email The email address
15  * @param int|string $s Size in pixels, defaults to 80px [ 1 - 512 ]
16  * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
17  * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
18  * @param bool $img True to return a complete IMG tag False for just the URL
19  * @param array $atts Optional, additional key/value attributes to include in the IMG tag
20  * @param string $schema
21  * @return String containing either just a URL or a complete image tag
22  * @source http://gravatar.com/site/implement/images/php/
23  */
24  public static function getImage($email, $schema = 'http', $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array())
25  {
26  $url = "$schema://www.gravatar.com/avatar/";
27  $url .= md5(strtolower(trim($email)));
28  $url .= "?s=$s&d=$d&r=$r";
29  if ($img) {
30  $url = '<img src="' . $url . '"';
31  foreach ($atts as $key => $val)
32  $url .= ' ' . $key . '="' . $val . '"';
33  $url .= ' />';
34  }
35  return $url;
36  }
37 }