Skip to content

A generic library to fetch users gravatar image or generate a custom one if none is found.

License

Notifications You must be signed in to change notification settings

chukwumaijem/js-gravatar

Repository files navigation

JS Gravatar

npm package

Demo

Vanilla JS

Copy dist/js-gravatar.js into your library folder Load it into your HTML script

<script type="text/javascript" src="path/to/js-gravatar.js"></script>

You can use the UNPKG link https://unpkg.com/[email protected]/dist/js-gravatar.js. Remember to update the package number to the most recent.

Call the method with its options.

JsGravatar({ element, numberOfDice: 2, callback });

With npm (and CommonJS builder)

Install with npm.

npm install --save js-gravatar

Install with yarn.

yarn add js-gravatar

import the library

ES5

const JsGravatar = require('js-gravatar');

ES6

import JsGravatar from 'js-gravatar';

Call the method

JsGravatar({ email: '[email protected]', size: 10, defaultImage: 'identicon' });
JsGravatar({ email: '[email protected]', defaultImage: 'monsterid' });

Parameter Definitions

  • email: Email address of the user to generate gravatar for - string
  • md5Hash: Optional: MD5 hash of the email above. If email is provided, md5hash will be ignored. If neither email nor md5hash is provided, the library will throw en error - string
  • size: Optional: The size of the image to be displayed. Should be from 1 to 2048 - number
  • defaultImage: What image should be used if email does not have a gravatar. See options below - string

Defaultimage Options - ['404', 'mp', 'identicon', 'monsterid', 'wavatar', 'retro', 'robohash', 'blank']

License

MIT License

About

A generic library to fetch users gravatar image or generate a custom one if none is found.

Resources

License

Stars

Watchers

Forks

Packages

No packages published