About Chris Morrell

I am a Philadelphia web designer and developer who focuses on PHP development and usable design. I am also the Director of IT for the International Association of Certified Home Inspectors.

Please Note: My site fell victim to a Wordpress security flaw a few weeks ago, and I'm just getting everything back to normal. Please bear with me.

I am currently not accepting any new clients.

Other Sites/Clients

Contact Me

If you need to get in touch with me, my name is Chris and my domain name is cmorrell.com. Think about it.

Simple PHP Pavatar Method

Posted by Chris Morrell on August 21st, 2008 in Misc

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!

1 Comment »

One Response to “Simple PHP Pavatar Method”

  1. Jeena Paradies

    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.

Leave a Reply

Additional comments powered by BackType

Comments & Trackbacks

You can leave a response, or trackback from your own site. Follow any responses to this entry through the RSS 2.0 feed.

More...


« Previous Post

@inxilpro

  • Wet Hot American Summer at World Cafe Live. It's free and dead. 2 days ago
  • Would really like something that combines Twitter starred + Google Reader starred/liked + Delicious.com. Does such a thing exist? 6 days ago
  • Also, how can OS X be so rock solid and other Apple-developed software be so buggy? 1 week ago
  • More updates...
Copyright © Chris Morrell, Powered by WordPress, Entry RSS Feed / Comment RSS Feed