Gravatar URL Generator API: The Complete Guide

Need to generate Gravatar URLs from email addresses? This guide covers everything you need to know about building Gravatar URLs via API, including MD5 hashing, default fallbacks, and implementation examples in multiple languages.

What is Gravatar?

Gravatar (Globally Recognized Avatar) is a service that associates user-uploaded profile pictures with email addresses. When someone signs up for a Gravatar-enabled site, their avatar appears automatically based on their email address.

Gravatar URLs are constructed from MD5 hashes of lowercase, trimmed email addresses, like: https://www.gravatar.com/avatar/0bc83cb571cd1c50ba6f3e8a78ef1346

How Gravatar Works

Gravatar URL generation follows these steps:

  1. Trim leading and trailing whitespace from the email
  2. Convert the email to lowercase
  3. Calculate the MD5 hash of the processed email
  4. Construct the URL with optional parameters
Pro Tip: Use our API to handle the hashing and URL construction automatically, avoiding common implementation mistakes.

Using the Gravatar URL API

TinyFn provides a simple endpoint to generate Gravatar URLs:

API Request
GET https://api.tinyfn.io/v1/gravatar?email=user@example.com
Headers: X-API-Key: your-api-key
Response
{
  "email": "user@example.com",
  "hash": "b58996c504c5638798eb6b511e6f49af",
  "gravatar_url": "https://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af",
  "gravatar_url_with_params": "https://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af?s=200&d=identicon"
}

Parameters

Parameter Type Description
email string The email address (required)
size integer Image size 1-2048 pixels (default: 80)
default string Fallback image: 404, mp, identicon, monsterid, wavatar, retro, robohash, blank
rating string Maximum rating: g, pg, r, x (default: g)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/gravatar?email=user@example.com&size=200&default=identicon',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(data.gravatar_url_with_params);
// Use in img tag
document.querySelector('.avatar').src = data.gravatar_url_with_params;

Python

import requests

response = requests.get(
    'https://api.tinyfn.io/v1/gravatar',
    params={'email': 'user@example.com', 'size': 200, 'default': 'retro'},
    headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(f"Gravatar URL: {data['gravatar_url_with_params']}")

cURL

curl "https://api.tinyfn.io/v1/gravatar?email=user@example.com&size=100" \
  -H "X-API-Key: your-api-key"

Default Image Options

Option Description
404Return 404 error if no Gravatar exists
mpMystery person silhouette
identiconGeometric pattern based on email hash
monsteridGenerated monster with unique features
wavatarGenerated face with unique features
retro8-bit arcade style pixelated face
robohashGenerated robot with unique features
blankTransparent PNG image

Best Practices

  1. Always set a default: Provide a fallback for users without Gravatars
  2. Use HTTPS: Always use secure Gravatar URLs
  3. Set appropriate rating: Use 'g' rating for general audiences
  4. Cache wisely: Gravatar URLs are deterministic; cache appropriately

Try the Gravatar URL API

Get your free API key and start generating Gravatar URLs in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key