The following code snippet shows how to generate Gravatar URLs from email address. This utility method alows you to pass the size of your email.

public String getGravatarUrl(String email, int size) {
    if (null == email) return null;

    final String hash = MD5Util.md5Hex(email.toLowerCase());
    final String gravtar = "";
    final String gravatarUrl = String.format(gravtar, hash, size);

    try {
        return URLEncoder.encode(gravatarUrl, "UTF-8");
    } catch (UnsupportedEncodingException e) {
    return null;
Tagged in : #Java


Please note: We reserve the right to delete comments that contains snarky remarks, offensive or off-topic. To know more read our comments policy.