How use Gravatar in your WebsiteWritten by Admin Sunday, 19 April 2015 18:37
As an example, let's say we start with "MyEmailAddress@example.com " (note the trailing space which our hypothetical user entered by mistake). If we md5 encode that string directly, we get the following (in PHP):
echo md5( "MyEmailAddress@example.com " ); // "f9879d71855b5ff21e4963273a886bfc"
If we now run that same email address through the above process, you will see that we get a different result (again in PHP):
$email = trim( "MyEmailAddress@example.com " ); // "MyEmailAddress@example.com" $email = strtolower( $email ); // "firstname.lastname@example.org" echo md5( $email ); // "0bc83cb571cd1c50ba6f3e8a78ef1346"
This can easily be combined into a single line:
echo md5( strtolower( trim( "MyEmailAddress@example.com " ) ) );
In addition to allowing you to use your own image, Gravatar has a number of built in options which you can also use as defaults. Most of these work by taking the requested email hash and using it to generate a themed image that is unique to that email address. To use these options, just pass one of the following keywords as the
d= parameter to an image request:
- 404: do not load any image if none is associated with the email hash, instead return an HTTP 404 (File Not Found) response
- mm: (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)
- identicon: a geometric pattern based on an email hash
- monsterid: a generated 'monster' with different colors, faces, etc
- wavatar: generated faces with differing features and backgrounds
- retro: awesome generated, 8-bit arcade-style pixelated faces
- blank: a transparent PNG image (border added to HTML below for demonstration purposes)
If for some reason you wanted to force the default image to always load, you can do that by using the
forcedefault= parameter, and setting its value to
Gravatar allows users to self-rate their images so that they can indicate if an image is appropriate for a certain audience. By default, only 'G' rated images are displayed unless you indicate that you would like to see higher ratings. Using the
rating= parameters, you may specify one of the following ratings to request images up to and including that rating:
- g: suitable for display on all websites with any audience type.
- pg: may contain rude gestures, provocatively dressed individuals, the lesser swear words, or mild violence.
- r: may contain such things as harsh profanity, intense violence, nudity, or hard drug use.
- x: may contain hardcore sexual imagery or extremely disturbing violence.
s=48 this is size 48px by 48px
Leave a comment
Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.
Latest from Admin
- [solved] How to delete text symbol from php line?
- [solved] How to delete all version from cource code in css & js files with your theme
- [solved] Deprecated: Methods with the same name as their class will not be constructors ... www/plugins/content/jw_sigpro/jw_sigpro.php on line 19
- Apple does not specifically show its announcements in other browsers. #appleshit
- [Schema.org] Micro-markup menu items