Skip to content

Instantly share code, notes, and snippets.

@csokol
Created July 22, 2013 11:34
Show Gist options
  • Save csokol/6053194 to your computer and use it in GitHub Desktop.
Save csokol/6053194 to your computer and use it in GitHub Desktop.
public String getPhoto(Integer width, Integer height) {
String size = width + "x" + height;
if (photoUri == null) {
String digest = Digester.md5(email);
String robohash = "http://robohash.org/size_"+size+"/set_set1/bgset_any/"+digest+".png";
String gravatar = "http://www.gravatar.com/avatar/" + digest + ".png?r=PG&size=" + size;
try {
return gravatar + "&d=" + java.net.URLEncoder.encode(robohash, "UTF-8");
} catch (UnsupportedEncodingException e) {
return gravatar;
}
} else {
return photoUri + "?width=" + width + "&height=" + height;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment