Microsoft Passport was a good idea. OpenID is a better idea. Gravatar is a good idea. Pavatar is a better idea. I think whenever a system can be open and decentralized, it should be (see my upcoming post on decentralized Twitter). For those of you who like the idea and want to use it, here’s a quick and dirty PHP method to get the Pavatar image for a given URL (supports all three Pavatar techniques)…
/**
* Determines a URL's associated Pavatar (http://pavatar.com/)
* Returns a URL on success, FALSE on failure
* Does NOT verify that the URL is a valid image
*
* @author Chris Morrell (http://cmorrell.com)
* @param string $url
* @return mixed
*/
function getPavatar($url)
{
// Grab Data
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($curl);
curl_close($curl);
// On Fail
if (!$page)
{
return false;
}
// X-Pavatar Header Method
elseif (preg_match('/X-Pavatar:\s*(.*?)(\s|\n)/i', $page, $matches))
{
return $matches[1];
}
// <link> Method
elseif (preg_match('/<link.*?rel="pavatar".*?>/i', $page, $matches))
{
preg_match('/href="(.*?)"/i', $matches[0], $matches);
return $matches[1];
}
// Default URL Method
else
{
$info = parse_url($url);
return "{$info['scheme']}://{$info['host']}/pavatar.png";
}
}
Usage:
$pavatar = getPavatar('http://cmorrell.com');
Enjoy!
Link to this post!
Related posts:
- 2 Simple Twitter UI Tweaks Update: it was bugging me, so I went ahead and...
- E-Mail Address Obfuscator Class A project I’m working on needs to output text that...