DiceBear as Gravatar default avatar
You can use the HTTP API of DiceBear as Gravatar default image. But before that, let's take a look at the conditions for Gravatar default images:
- ✅ MUST be publicly available (e.g. cannot be on an intranet, on a local development machine, behind HTTP Auth or some other firewall etc). Default images are passed through a security scan to avoid malicious content.
- ✅ MUST be accessible via HTTP or HTTPS on the standard ports, 80 and 443, respectively.
- ⚠️ MUST have a recognizable image extension (jpg, jpeg, gif, png, heic)
- ⚠️ MUST NOT include a querystring (if it does, it will be ignored)
Since Gravatar does not support SVG, we have to use the PNG endpoint.
js
const emailHash = encodeURIComponent('00000000000000000000000000000000');
const defaultImage = encodeURIComponent(
'https://api.dicebear.com/10.x/lorelei/svg'
'https://api.dicebear.com/10.x/lorelei/png'
);
const gravatarImage = `https://www.gravatar.com/avatar/${emailHash}?d=${defaultImage}`;
// https://www.gravatar.com/avatar/00000000000000000000000000000000?d=https%3A%2F%2Fapi.dicebear.com%2F10.x%2Florelei%2Fpngphp
$emailHash = urlencode('00000000000000000000000000000000');
$defaultImage = urlencode(
'https://api.dicebear.com/10.x/lorelei/svg'
'https://api.dicebear.com/10.x/lorelei/png'
);
$gravatarImage = sprintf(
'https://www.gravatar.com/avatar/%s?d=%s',
$emailHash,
$defaultImage
);
// https://www.gravatar.com/avatar/00000000000000000000000000000000?d=https%3A%2F%2Fapi.dicebear.com%2F10.x%2Florelei%2Fpngpython
import urllib.parse
email_hash = urllib.parse.quote("00000000000000000000000000000000")
default_image = urllib.parse.quote(
"https://api.dicebear.com/10.x/lorelei/svg"
"https://api.dicebear.com/10.x/lorelei/png"
)
gravatar_image = f"https://www.gravatar.com/avatar/{email_hash}?d={default_image}"
# https://www.gravatar.com/avatar/00000000000000000000000000000000?d=https%3A%2F%2Fapi.dicebear.com%2F10.x%2Florelei%2Fpnggo
import (
"fmt"
"net/url"
)
emailHash := url.QueryEscape("00000000000000000000000000000000")
defaultImage := url.QueryEscape(
"https://api.dicebear.com/10.x/lorelei/svg",
"https://api.dicebear.com/10.x/lorelei/png",
)
gravatarImage := fmt.Sprintf("https://www.gravatar.com/avatar/%s?d=%s", emailHash, defaultImage)
// https://www.gravatar.com/avatar/00000000000000000000000000000000?d=https%3A%2F%2Fapi.dicebear.com%2F10.x%2Florelei%2FpngUsually we set options in the query string, such as the seed. Since a query string is not allowed by Gravatar, the HTTP-API allows you to specify the options in the path. Just replace the question mark with a slash and encode the options.
js
const emailHash = encodeURIComponent('00000000000000000000000000000000');
const options = `seed=${emailHash}`;
const defaultImage = encodeURIComponent(
`https://api.dicebear.com/10.x/lorelei/png?${options}`
`https://api.dicebear.com/10.x/lorelei/png/${encodeURIComponent(options)}`,
);
const gravatarImage = `https://www.gravatar.com/avatar/${emailHash}?d=${defaultImage}`;
// https://www.gravatar.com/avatar/00000000000000000000000000000000?d=https%3A%2F%2Fapi.dicebear.com%2F10.x%2Florelei%2Fpng%2Fseed%253D00000000000000000000000000000000php
$emailHash = urlencode('00000000000000000000000000000000');
$options = sprintf('seed=%s', $emailHash);
$defaultImage = urlencode(
'https://api.dicebear.com/10.x/lorelei/png?' . $options
'https://api.dicebear.com/10.x/lorelei/png/' . urlencode($options)
);
$gravatarImage = sprintf(
'https://www.gravatar.com/avatar/%s?d=%s',
$emailHash,
$defaultImage
);
// https://www.gravatar.com/avatar/00000000000000000000000000000000?d=https%3A%2F%2Fapi.dicebear.com%2F10.x%2Florelei%2Fpng%2Fseed%253D00000000000000000000000000000000python
import urllib.parse
email_hash = urllib.parse.quote("00000000000000000000000000000000")
options = f"seed={email_hash}"
default_image = urllib.parse.quote(
f"https://api.dicebear.com/10.x/lorelei/png?{options}"
f"https://api.dicebear.com/10.x/lorelei/png/{urllib.parse.quote(options)}"
)
gravatar_image = f"https://www.gravatar.com/avatar/{email_hash}?d={default_image}"
# https://www.gravatar.com/avatar/00000000000000000000000000000000?d=https%3A%2F%2Fapi.dicebear.com%2F10.x%2Florelei%2Fpng%2Fseed%253D00000000000000000000000000000000go
import (
"fmt"
"net/url"
)
emailHash := url.QueryEscape("00000000000000000000000000000000")
options := fmt.Sprintf("seed=%s", emailHash)
defaultImage := url.QueryEscape(
fmt.Sprintf("https://api.dicebear.com/10.x/lorelei/png?%s", options),
fmt.Sprintf("https://api.dicebear.com/10.x/lorelei/png/%s", url.QueryEscape(options)),
)
gravatarImage := fmt.Sprintf("https://www.gravatar.com/avatar/%s?d=%s", emailHash, defaultImage)
// https://www.gravatar.com/avatar/00000000000000000000000000000000?d=https%3A%2F%2Fapi.dicebear.com%2F10.x%2Florelei%2Fpng%2Fseed%253D00000000000000000000000000000000