Integrating Gravatar with your blog

Friday 02 December 2011

Today I integrated Gravatar with my blog so, for commenters who have a Gravatar account, you'll now see an avatar next to their blog post comments.

As long as you have a commenter's email address it's very easy to display their avatar.

In Coldfusion simply convert the commenter's email address to lower case, hash it, convert it to lower case again and add it to an IMG tag as follows.

<img src="http://www.gravatar.com/avatar/#Lcase( Hash( Lcase( commenter_email ) ) )#" />

When uploading an avatar to the Gravatar web site you are required to apply a rating to it.

Gravatar Ratings

  • G rated: suitable for display on all websites with any audience type.
  • PG rated: may contain rude gestures, provocatively dressed individuals, the lesser swear words, or mild violence.
  • R rated: may contain such things as harsh profanity, intense violence, nudity, or hard drug use.
  • X rated: may contain hardcore sexual imagery or extremely disturbing violence.

To ensure X rated avatars do not appear on your site simple append ?r=R to the URL like so:

<img src="http://www.gravatar.com/avatar/#Lcase( Hash( Lcase( commenter_email ) ) )#?r=R" />

Now only avatars that are R rated and below will be displayed.

Finally, if the commenter does not have a Gravatar account a placeholder image is displayed. You can override the default image and display one of your own by appending an image URL like so:

<img src="http://www.gravatar.com/avatar/#Lcase( Hash( Lcase( commenter_email ) ) )#?r=R&d=http%3A%2F%2Fwww.example.com%2Fyourplaceholderimage.jpg" />

Tags

ColdFusion (13) HTML (7)

Share


Comments

Raymond Camden I've often wondered - are there actually X rated Gravatar images?

Posted by Raymond Camden on Monday 05 December 2011 at 02:19 GMT

Simon Bingham The mind boggles! :)

Posted by Simon Bingham on Monday 05 December 2011 at 09:20 GMT

Lola J. Lee Beno Yeah . . . what Ray asked.

Posted by Lola J. Lee Beno on Monday 12 December 2011 at 14:18 GMT

Add Comment

Your email address will not be displayed on this blog.

The URL of your blog or web site.