I'd like to add gravatar support to my Joomla article. How can I do that?
Take a look at the Gravatar PHP documentation. Basically, you want to generate a URL for the image to be displayed. This URL is based on the users email address, and will of course only work for logged in users.
The following code should give you a starting point:
<?php $user = JFactory::getUser(); $default = "http://www.example.com/default.jpg"; // default image if no gravatar $size = 40; // 1 - 2048 pixels $grav_url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $user->email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size; ?> <img src="<?php echo $grav_url; ?>" alt="" />
There are many options available for default image, size, rating etc. See the Gravatar documentation for more info.
As for how to use the code, it depends on what you mean by
add gravatar support to my Joomla article. You can build a plugin, create an override, or use a custom HTML module that supports PHP code.