Use Gravatar in First-party Systems
Gravatar (Globally Recognised Avatar) is a service that associates avatar images with email addresses. When a user registers on your platform with their email, you can display their Gravatar as a default avatar without building your own image upload and storage pipeline.
How It Works
Gravatar exposes a simple HTTP endpoint. You compute the SHA256 hash of the user's lowercased and trimmed email address, then embed it in an image URL:
Generating the Hash
Node.js
Python
Shell
URL Parameters
The /avatar/ endpoint accepts several query parameters to customise the result:
Default Image Options (d)
identicon— a geometric pattern based on the hashrobohash— a generated robot imageretro— an 8-bit style pixelated facemonsterid— a generated monster cartoonwavatar— a generated facemp— a generic silhouette (Mystery Person)blank— a transparent PNG- A custom URL (must be URL-encoded)
Putting It Together
Always pass the d parameter to avoid broken images for users who have not set up a Gravatar. identicon and
robohash are popular choices because they generate a unique, recognisable image for every hash.
gravataravatar