Ruby Gravatar Link generator

Just a simple example of Ruby code to generate a gravatar link, substitute the with the desired address and you will get the something like:

In the second use case you can specify the size of the gravatar, the default image in case no gravatar is found and the rating:


#!/usr/bin/env ruby
require 'digest/md5'
require 'uri'
# this is based on gravatar image API
# options :
# size : <integer> size of image
# default: <string> url of image if email not found or:
# * 404
# * mm
# * identicon
# * monsterid
# * wavatar
# * retro
# * blank
# forcedefault: "y" force default image to load
# rating: <string> one of the values : g, pg, r, x
def gravatar email, options={}
  email_md5 = Digest::MD5.hexdigest email
  params_query = URI.encode_www_form(options) unless options.empty?
puts gravatar('')
puts gravatar('',
              size: 200,
              default: '404',
              rating: 'pg'
Tagged , ,