Tutorials Java How to Generate Gravtar Image Url from Email in Java

How to Generate Gravtar Image Url from Email in Java

The following code snippet shows how to generate Gravatar URLs from email address. This utility method allows 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 = "http://www.gravatar.com/avatar/%s?s=%s&r=g&d=404";
    final String gravatarUrl = String.format(gravtar, hash, size);

    try {
        return URLEncoder.encode(gravatarUrl, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}
Total
0
Shares
guest
0 Comments
Inline Feedbacks
View all comments
Previous Post

How to Generate Unique File Name When Saving a File in Java

Next Post
Android Tutorials

Convert DP Unit to Equivalent Pixels in Android

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
0
Would love your thoughts, please comment.x
()
x