PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Web Services » Services_Libravatar » Manual

Services_Libravatar is a PHP5 library to the Libravatar service that delivers avatar pictures to other websites: It gives you image URLs for email addresses. Libravatar offers several benefits over the classic Gravatar service: It is federated - you can host the avatar server for your mail addresses yourself. It is open source. It can fall back to Gravatar if Libravatar does not have a picture for the email address, making it perfectly backwards compatible. It allows you to give a picture to your OpenID.

Basic usage

After including the base Services_Libravatar file, create an object of the class. You may set default options for image size, default url, HTTPS mode and hashing algorithm.

After you created the Services_Libravatar instance, call Services_Libravatar::getUrl() on it with the email as parameter.

Creating a libravatar instance

<?php
require_once 'Services/Libravatar.php';
$sla = new Services_Libravatar();
$sla->setSize(256)
    ->setDefault('identicon');

$url = $sla->getUrl('foo@example.org');
?>

Instead of manually deciding if you need HTTPS or not, Services_Libravatar will detect that automatically when calling detectHttps().

If you temporarily need different options for one image, you may pass them as option array as second parameter to getUrl(). They will override the class options that were configured via the set*() methods, but only for the current getUrl() call:

Using temporary options

<?php
require_once 'Services/Libravatar.php';
$sla = new Services_Libravatar();
$sla->setSize(256)
    ->setDefault('identicon');

$url1Big   = $sla->getUrl('foo@example.org');//size 256
$url1Small = $sla->getUrl(
    'foo@example.org',
    array('size' => 32, 'default' => '404')
);

//size 256 again
$url2Big = $sla->getUrl('bar@example.org');
?>