Option #1: Ruby Reference Implementation

# include MD5 gem, should be part of standard ruby install
require 'MD5'

# get the email from URL-parameters or what have you and make lowercase
email_address = params[:email].downcase

#create the md5 hash
hash = MD5::md5(email_address)

# compile URL which can be used in <img src=""...
image_src = "http://www.gravatar.com/avatar/#{hash}" />

Option #2: Ruby Avatar Gem

See: http://avatar.rubyforge.org/

an joint