Ben Ripkens

back to blog index

Gravatar for Java applications

Gravatar for Java (actually Gravatar4Java) is a small library for the generation of Gravatar URLs. For those readers who don’t know Gravatar - Gravatar allows you to have one avatar everywhere by uploading it to the Gravatar website. Other websites can then automatically retrieve an avatar for a user by using the email address as an identifier.

There is already a Java library around Gravatar by Ralf Ebert but it lacks some of the newer functionality like avatar over HTTPS or custom default avatars. Additionally it’s not a Maven project nor hosted on Maven Central, thus enough reasons to write my own.

The Gravatar4Java project is hosted on GitHub and already available in Maven Central (actually my first project in Maven Central)! Following is the typical Maven dependency snippet, a plain Java example and a Spring beans definition for the library.

<dependency>
  <groupId>de.bripkens</groupId>
  <artifactId>gravatar4java</artifactId>
  <version>1.1</version>
</dependency>
import de.bripkens.gravatar.DefaultImage;
import de.bripkens.gravatar.Gravatar;
import de.bripkens.gravatar.Rating;

// ...

String gravatarImageURL = new Gravatar()
    .setSize(50)
    .setHttps(true)
    .setRating(Rating.PARENTAL_GUIDANCE_SUGGESTED)
    .setStandardDefaultImage(DefaultImage.MONSTER)
    .getUrl("foobar@example.com");</pre>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:p="http://www.springframework.org/schema/p">

    <!-- Gravatar -->
    <bean id="gravatar"
          class="de.bripkens.gravatar.Gravatar"
          p:size="75"
          p:rating="GENERAL_AUDIENCE"
          p:standardDefaultImage="MONSTER" />

</beans>
That's me, Ben.
Hey, I am Ben Ripkens (bripkens) and this is my blog. I live in Düsseldorf (Germany) and I am employed by the codecentric AG as a Software Engineer. Web application frontends are my main area of expertise, but you may also find some other interesting articles on this blog.