ColdFusion Image Requests

← Back

Contributed by Rob Cameron

Although there isn't a plugin available for ColdFusion, it is extremely easy to code yourself. ColdFusion has a function available which will automatically create an MD5 Hash of any string you specify. This means that you simply create the link to the gravatar yourself and include the poster's email address inside the #lcase(Hash(lcase()))# functions.

Usage:

<img src="https://www.gravatar.com/avatar/#lcase(Hash(lcase(user_email)))#" />

Where user_email is the email of the poster that you want to retrieve the gravatar for.

If you wish to restrict your gravatars to R rated and below, your link would look like this:

<img src="https://www.gravatar.com/avatar/#lcase(Hash(lcase(user_email)))#?r=R" />

If you want R rated gravatars and below, and you want to use your own image as a default graphic (shows up when either no gravatar exists for a given user, or the given user's gravatar exceeds the specified rating), you'd do this:

<img src="https://www.gravatar.com/avatar/#lcase(Hash(lcase(user_email)))#?r=R&d=http%3A%2F%2Fwww.yoursite.com%2Fsomeimage.jpg" />

And, of course, let's not forget to add an alt attribute:

<img src="https://www.gravatar.com/avatar/#lcase(Hash(lcase(user_email)))#?r=R&d=http%3A%2F%2Fwww.yoursite.com%2Fsomeimage.jpg" alt="#user_name#'s Gravatar" />

For extra credit you could even create a custom tag for yourself that would output the entire image tag.