Libraries

If a library or plugin is not availble for your language or application, your best option at the moment is to use our simple API. Don't worry though, it's really not that much work!

C#

Chris Forbes is maintaining the C# bindings.

using libravatarsharp;
var uri = AvatarUri.FromEmail( "someone@example.com" );

(!) The library does not support federation.

Common Lisp

There is a library supporting both Gravatar, Libravatar and Unicornify.

Haskell

The Libravatar library is maintained by fr33domlover and is available on hackage.

import Network.Libravatar
myUrl = avatarUrl (Right "http://example.com/id/john") True Nothing (Just 100)

Java

Alessandro Leite has created a library in Java.

(!) The library does not support federation.

Nim

A tiny Nim library. Federation is not supported by design as DNS discovery is left to the user.

(!) The library does not support federation.

node.js

There is a Libravatar node.js module that can be used in the following way:

var libravatar = require('libravatar');
libravatar.url(email='person@example.com', openid=null, { size: 96, default: 'mm' }, https=false,
  function (error, avatar_url) {
    console.log('<img src="' + avatar_url + '">');
  });

You can also use the ember-cli module.

Perl

The Libravatar::URL module is part of the Gravatar::URL package (libgravatar-url-perl in Debian and Ubuntu) since version 1.03.

use Libravatar::URL;
my $avatar_url = libravatar_url(email => 'person@example.org');
print '<img src="' . $avatar_url . '">';

As of version 1.04, you can also use OpenID URLs instead of email addresses:

my $avatar_url = libravatar_url(openid => 'https://example.com/id/person');

PHP

Melissa Draper maintains the Services_Libravatar PEAR package. Here's an example of how it works:

require_once 'Services/Libravatar.php';
$libravatar = new Services_Libravatar();
$avatar_url = $libravatar->getUrl('person@example.org');
print '<img src="' . htmlspecialchars($avatar_url) . '" alt="avatar"/>';

or like this for OpenID-based avatars served over HTTPS:

$avatar_url = $libravatar->getUrl('http://example.org/id/Person', array('https' => true));

Python

The pyLibravatar module can be used like this:

from libravatar import libravatar_url
avatar_url = libravatar_url(email = 'person@example.org')
print '<img src="' + avatar_url + '">'

Qt5

The source code for Rawatar can be found on git.kde.org

Ruby

There is a Ruby library for Libravatar named Vishnu, published as the Ruby gem vishnu. Example usage of Vishnu:

require 'vishnu'
Vishnu.new(email:  'someone@example.com').url   # get avatar for email
Vishnu.new(openid: 'https://example.com').url   # get avatar for OpenID URL

Previously, Kang-min Liu created a Ruby library named Libravatar, published as the Ruby gem libravatar. As of 2020 the library appears to be unmaintained – it has some ignored issues and pull requests that were created four years ago.

require 'libravatar'
avatar_url = Libravatar.new(:email => 'person@example.org')
# or avatar_url = Libravatar.new(:openid => 'https://example.com/id/person')
print '<img src="', avatar_url, '">'

Shell

Gravatarhash is a pure shell utility supporting Libravatar and Gravatar.

Symfony

Julien Fastré has a created a Libravatar bundle for the PHP framework Symfony.

Twisted

The txLibravatar module can be used like this:

from txlibravatar import libravatar_url
d = libravatar_url(email = 'person@example.com')
d.addCallback(lambda x: print '<img src="' + x + '">')

Go

The go-libravatar module can be used like this:

import "strk.kbt.io/projects/go/libravatar"
avt := libravatar.New()
avatar_url := avt.FromEmail("person@example.com")

or, with global context

avatar_url := libravatar.FromEmail("person@example.com")

Plugins

There aren't many plugins available at the moment, but please suggest the ones you'd like to have.

Contribute!

Writing a library in your language of choice is not very hard but here are a few guidelines to help you produce a library that will be as complete as possible:

  • Read the API documentation carefully.
  • Make sure you normalize emails and OpenID URLs according to the rules.
  • Email hashes should default to MD5 (for the Gravatar redirection to work) while SHA256 is the only hash allowed for OpenID hashes.
  • The base URL should be looked up in DNS to ensure that federation is possible.
  • SRV weight and priority handling is tricky. Have a look at srv_hostname() to see how it's done in the CPAN module.

If you have any questions or run into any problems, come talk to us. Moreover if you are interested in writing a plugin for your favourite framework/CMS or a library for your favourite language get in touch too, we would be more than happy to link to them from this page!