Getting gravatar images with Ruby on Rails

What Is Gravatar?

An “avatar” is an image that represents you online—a little picture that appears next to your name when you interact with websites.A Gravatar is a Globally Recognized Avatar. You upload it and create your profile just once, and then when you participate in any Gravatar-enabled site, your Gravatar image will automatically follow you there.

Understanding how to get images from Gravatar

When you sign up in gravatar, you need to register an unique e-mail. Gravatar uses that email address to generate an unique MD5.hexdigest key, and then, it links that key to your image file.

Let’s take a look at my gravatar  image url:

http://gravatar.com/avatar/1c7b91342323ab699f6668f3317ed1bb

Parameter after the avatar is the MD5.hexdigest key generated with your email, let’s try generate that in our application and check if it gives the same result:


require "digest/md5"
Digest::MD5.hexdigest('meghagulati30@gmail.com').to_s

Result is “1c7b91342323ab699f6668f3317ed1bb”

So now you can write your own tool to get the gravatar user image: just use the email to generate the key and append it to the url.

If you are looking for more options while fetching the image you can use gems like gravtastic which lets you get images of different sizes, avatar rating and different filetype.

Advertisements

One thought on “Getting gravatar images with Ruby on Rails

  1. Hi,
    Thanks for providing information about Ruby on Rails apllication. This information will definitely help in Ruby on Rails Outsourcing to build rich and dynamic web applications.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s