Gravatar default images - a better way

At Harmonypark we decided to put gravatars into one of our applications (which is so easy it’s not funny) – and when the time came to select the default images for the gravatar I piped up: “I know how to fix this!” and pointed to a blog post I wrote about it long ago: (You can read it here.)
My colleague Ebony came up with a great solution:

“Why not use another gravatar as the default image.”

Which is an utterly brilliant idea – that way the default image gravatar will scale correctly, and we wouldn’t have to mess around with having different image sizes for the different scaled default images. Here’s how we did it:

1) Go to and add a default gravatar for some email address that you won’t use.

2) Install the gravatar plugin


3) Extend the gravatar plugin to allow for a default email address by putting this code in lib/gravatar_extension.rb (remember to include this file in a initializer).

module GravatarHelper  
  module PublicMethods  
    def gravatar_for_with_default(object, options={})
      options.merge!(:default =>  
           gravatar_url("", options))
      gravatar_for_without_default(object, options)  
alias_method_chain :gravatar_for, :default  



4) Now, everytime a user is missing a gravatar, the default image will be your default gravatar, this will handle all the awesome scaling stuff that gravatar does too

Subscribe via RSS

Back to all blog posts