Gravatar CakePHP Helper

An independent Avatar-Generator

90% of all blogs out there use gravatar. Therefore you can easily use it with most of your users’ email addresses.
But even if you don’t want your users to use their gravatar image you can still use the funny images this service provides. Instead of an email address you could hash the user_id of the member and get a unique image to display as avatar in the profiles or even throughout the website.

Gravatar Helper and its Test Case.

Example usage

# using the email of the user
echo $this->Gravatar->image($email, array('default'=>'retro', 'title'=>__('Avatar', true)));

# using an unique identifier - in this case the user_id
echo $this->Gravatar->image($uid, array('size'=>'20', 'default'=>'monsterid', 'title'=>__('Avatar', true)));

The first example will try to find the real image the user has submitted to gravatar and will fallback to some colorful and unique retro image.
The second example uses little monster figures for all users (since the user_id cannot be an email and therefore there cannot be any custom user image – except for collisions with the md5 hash maybe).

Tip: check out the test case for all possible image types, options and scenarios.
If you open my test case with the browser (…/test.php?case=helpers%5Cgravatar.test.php&plugin=tools) you will see the images as I echoed them out for testing purposes.

The main part of this helper is the work of Graham Weldon. I simply added some enhancements.
Hava fun.

0.00 avg. rating (0% score) - 0 votes

1 Comment

  1. Hi Mark
    the above provided links are broken: could you please telle me the link to download gravatar helper?
    Thanks in advance


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.