user3259486
user3259486

Reputation: 139

Gravatar image in my static webite

I need to import current gravatar image in my website so that no matter when they change it in the gravatar it will automatically change it in my website...

I dont want php, python nor any such... I just need a simple link.. or may be simple javascript.. that I could include in the IMG tag that would automatically change the picture when they change in gravatar and in my website.

I tried to use php script but I dont want to use php.

I need a simple solution for a site ending with .html page.

Upvotes: 1

Views: 2494

Answers (3)

Mike Christensen
Mike Christensen

Reputation: 91608

First, you'll need to create an MD5 Hash of the email address. You can use Crypto-JS for this. Note, you'll want to convert the email address to all lowercase and trim any spaces off.

Next, you'll have to create an image using the proper URL. Basically, the format for this is http://www.gravatar.com/avatar/<Hash> where <Hash> is the hash you just created.

This appears to work, at least for my email address:

<html>
<body>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>
<script>
   var hash = CryptoJS.MD5("[email protected]");
   document.write('<img src="http://www.gravatar.com/avatar/' + hash + '" />');
</script>
</body>
</html>

Fiddle

Upvotes: 0

Timothy Shields
Timothy Shields

Reputation: 79461

The extremely simple API is described here: http://en.gravatar.com/site/implement/images/

  1. Take user email address.
  2. Hash it.
  3. Use http://www.gravatar.com/avatar/{hash}.

(All I did was Google "Gravatar API." It wouldn't have been hard to do that yourself.)

Upvotes: 2

Jagjot
Jagjot

Reputation: 6136

Check this jQuery library https://github.com/zachleat/jQuery-Gravatar

And it's demo here http://www.zachleat.com/javascript/gravatar/index.html

Upvotes: 2

Related Questions