The libgravatar library contains an API for gravatar.