Gravatar
lastmod 2025-02-14created 2014-09-118 edits
While browsing other websites, you may have noticed that many users show a picture next to their names. These pictures are called "avatars". WordPress uses a specific type of avatar called a "Gravatar" – short for "Globally Recognized Avatar". Unlike standard avatars, a Gravatar follows you around the web and is displayed automatically when you comment on a WordPress site.
Example
JavaScript
const md5 = require( 'md5' );
function getGravatarURL( email, size = 80 ) {
// Trim leading and trailing whitespace from
// an email address and force all characters
// to lower case
const address = String( email ).trim().toLowerCase();
// Create an MD5 hash of the final string
const hash = md5( address );
// Grab the actual image URL
return `https://www.gravatar.com/avatar/${ hash }?s=${ size }`;
}
bash
#!/bin/bash
# This script downloads a gravatar image associated with EMAIL and saves it at
# AVATAR_OUTPUT_PATH then creates a favicon icon and saves it at
# FAVICON_OUTPUT_PATH.
EMAIL="[email protected]"
AVATAR_OUTPUT_PATH="static/img/avatar.png"
FAVICON_OUTPUT_PATH="static/favicon.ico"
# https://en.gravatar.com/site/implement/hash/
function email_to_hash {
echo -n $1 | tr '[A-Z]' '[a-z]' | md5
}
# Stop on error.
set -e
email_hash=$(email_to_hash $EMAIL)
# https://en.gravatar.com/site/implement/images/
wget http://www.gravatar.com/avatar/$email_hash?size=512 -O $AVATAR_OUTPUT_PATH
# http://www.imagemagick.org/Usage/thumbnails/#favicon
convert $AVATAR_OUTPUT_PATH -bordercolor white -border 0 \
\( -clone 0 -resize 16x16 \) \
\( -clone 0 -resize 32x32 \) \
\( -clone 0 -resize 48x48 \) \
\( -clone 0 -resize 64x64 \) \
-delete 0 -alpha off -colors 256 $FAVICON_OUTPUT_PATH
Favorite site
Pages that link here