I was looking for a WordPress plugin to spice up comments with custom avatars, but I didn’t find exactly what I was looking for. So I hacked together the Ravatar WordPress plugin that will display a randomly generated avatar for each visitor. The icons are based on email, so a given visitor will get the same icon each time they comment. It’s totally customizable, so you can set it up with images that match your blog’s theme. Visitors can optionally choose their own avatar by setting up a Gravatar. Download the plugin here.

[Update: Ravatars is currently unsupported and is no longer used on this site.]

The Ravatar plugin is based on Shamus Young’s Wavatar plugin which is quite good, but the generated avatars weren’t really what I was looking for.

Ravatar comes with a default set of images, or you can remove those and upload your own. It works by creating a hash of the email address, and then using the hash to choose an image and the place where the image should be cropped. Uploading your own images gives you the power to customize avatars for your site. A backpacking site might use use nature scenes. Or you might pick images that match your blog’s color scheme.

Here is a set of avatars that were generated by the plugin’s default images. I grabbed some images of oil paintings from Wikimedia Commons for the defaults.

default ravatars screenshot

To customize the plugin, upload your own set of images to the plugins/ravatars/parts directory. Supported image types are .jpg and .png. Its hard to say how many images you should upload. The minimum for a good set of ravatars is probably around 40, but you will want more if you have a lot of people posting and you want avatars to be unique for everybody. Try to get images with a lot of distinctive elements in them. If any images have large sections of one solid color, cropping those sections out will give you a more varied set of ravatars.

Here is a set of avatars Ravatar generated using the source images for my site (which are different from the Ravatar default images). I picked a set of HDR images that are mostly industrial, plus a few nature scenes. Leave a comment below to see what your own avatar looks like.

custom ravatars screenshot

To install the plugin, get it here, unzip it, put it in the wordpress plugins directory, and enable it. Thats all there is to it.

The administration panel is under Options » Ravatars. You can adjust the size of the Ravatars, and assign HTML to come before and after each image to help nudge it into place. Each image is also set with the CSS “ravatars” class, so you can fine-tune the avatar position in your CSS file. For easy deployment, icons will automatically precede the commenter’s name.

If that still doesn’t give you enough control over ravatar placement and you don’t mind editing your theme, just turn off automatic placement and add the line

ravatar_show($comment->comment_author_email);

to your comment loop wherever you want the image to appear.

Note that the plugin requires that your install of PHP support the GD library. If it doesn’t, the Ravatars won’t show up and you’ll get a warning in the Ravatar admin panel. You can still use this plugin to display Gravatars, even if the GD library isn’t available. Image manipulation functions are very memory intensive. If you get a memory error, try reducing the size of your source images by lowering the resolution or cropping them into smaller parts. You can also increase PHP’s memory_limit.

The readme.txt file that comes with the plugin contains a few other tips and tricks for using the plugin, so have a look at that if you are having trouble.

Like this plugin? Make a donation.