Skip to content

Instantly share code, notes, and snippets.

@dommmel
Created October 17, 2013 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dommmel/7024623 to your computer and use it in GitHub Desktop.
Save dommmel/7024623 to your computer and use it in GitHub Desktop.
Retrieve Gravatar indenticon for a given email address via javascript. You need to include a md5 library (like http://www.myersdaily.org/joseph/javascript/md5-text.html)
# get the url of an emails gravatar image
#
# default_image can either be an image url or one of the following: mm, identicon, monsterid, wavatar, retro, blank
# (See https://de.gravatar.com/site/implement/images/ for all options)
#
# Example usage:
# get_gravatar_image_url("example@example.com", 80, "retro")
get_gravatar_image_url = (hashed_email, size=80, default_image="mm", force_default=false) ->
size = (if (size >= 1 and size <= 2048) then size else 80)
"http://www.gravatar.com/avatar/#{hashed_email}?size=#{size}&d=#{encodeURIComponent(default_image)}" + (if force_default is true then "&f=y" else '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment