SQLTerminal.app
now available

XPath.app
now available
Want fresh tech tips in your inbox?

Generate a Gravatar URL with Ruby

       

To get a Gravatar you need to hash an email address with the MD5 algorithm.

MD5 is a part of the Ruby standard library. Rails loads it by default, but otherwise you will have to require it yourself.

This is a simple implementation.

Gravatar supports other features, such as ratings and sizes. But the code below just hashes an email and constructs the Gravatar URL.

It also sets a default image using the ?d param, in case you need a default image.

require 'digest/md5'
# gravatar("someone@example.com")
def gravatar(email)
    base_url = "http://gravatar.com/avatar/"
    hashed_email = Digest::MD5.hexdigest(email)
    default_image =  "?d=http://example.com/path/to/default-image.jpg"
    [base_url, hashed_email, default_image].join
end

The image I used for the default doesn't exist. Replace it with your own default image.

Tagged w/ #ruby #gravatar #images

Apps I've Built

XPath Expression Editor
Practice and improve your XPath skills with XPath Editor
Click to buy on the App Store
Photo Location Changer
Easily change the location on your photos and videos
Click here for more info about the app
Photo Date Changer
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app