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!
Additional comments powered by BackType
You can leave a response, or trackback from your own site. Follow any responses to this entry through the RSS 2.0 feed.
Hi, your “Default URL Method” is not quite right, It does not look at http://example.com/myname/pavatar.png, but that’s not such a big deal, I was thinking about removing this method anyway.