An open API service indexing awesome lists of open source software.

https://github.com/xn-02f/gravatar

🖼 A library to generate gravatar image url.
https://github.com/xn-02f/gravatar

avatar gravatar js

Last synced: 5 months ago
JSON representation

🖼 A library to generate gravatar image url.

Awesome Lists containing this project

README

          

# Gravatar

[![Actions](https://img.shields.io/github/actions/workflow/status/xn-02f/gravatar/test.yml?style=flat-square&logo=github)](https://github.com/xn-02f/gravatar/actions)
[![npm](https://img.shields.io/npm/v/@xn-02f/gravatar.svg?style=flat-square&logo=npm)](https://www.npmjs.com/package/@xn-02f/gravatar)
[![LICENSE](https://img.shields.io/github/license/xn-02f/gravatar.svg?style=flat-square&logo=opensourceinitiative)](https://github.com/xn-02f/gravatar/blob/main/LICENSE)

> 🖼 `Gravatar` is a node library to generate gravatar image url.

## Install

Via npm :

```bash
npm i @xn-02f/gravatar
```

> [!NOTE]
> This library was moved to ESM from `v2`.
>
> If ESM doesn't work well with your node version, switch to the `1.x` version for CJS compatibility.

## Usage

```javascript
const gravatar = require('@xn-02f/gravatar')

const email = 'i@xn--02f.com'
const options = {size: '80', default: '404'}
gravatar(email, options)
```

| Parameter | Description |
| --- | --- |
| email | `string`
The gravatar email url. |
| options | `object`
Query string options. Like: `size`, `default`, `rating`, `forcedefault` and [others](https://en.gravatar.com/site/implement/images/). |

### About options parameter

| Property | Alias | Default | Description |
| --- | --- | --- | --- |
| size | `s` | 80 | Request a specific image size, which will be dynamically delivered from Gravatar and passing a single pixel dimension.
(since the images are square) |
|default | `d` | ![defaultImage](https://www.gravatar.com/avatar/00000000000000000000000000000000?s=25) | Set default image when an email address has no matching Gravatar image.
Gravatar has a number of built in options:
`404` do not load any image if none is associated with the email hash, instead return an HTTP 404 (File Not Found) response.
`mp` ![mp](https://www.gravatar.com/avatar/00000000000000000000000000000000?s=20&d=mp)
`identicon` ![identicon](https://www.gravatar.com/avatar/00000000000000000000000000000000?s=20&d=identicon)
`monsterid` ![monsterid](https://www.gravatar.com/avatar/00000000000000000000000000000000?s=20&d=monsterid)
`wavatar` ![wavatar](https://www.gravatar.com/avatar/00000000000000000000000000000000?s=20&d=wavatar)
`retro` ![retro](https://www.gravatar.com/avatar/00000000000000000000000000000000?s=20&d=retro)
`robohash` ![robohash](https://www.gravatar.com/avatar/00000000000000000000000000000000?s=20&d=robohash)
`blank` ![blank](https://www.gravatar.com/avatar/00000000000000000000000000000000?s=20&d=blank) |
| forcedefault
(Unrecommend) | `f` | (null) | If for some reason you wanted to force the default image to always load, you can do that by using the parameter, and setting its value to `y`.
Before: ![before](https://www.gravatar.com/avatar/11b334f003ef029c9d154f5dbae18b44?s=25)
After: ![after](https://www.gravatar.com/avatar/11b334f003ef029c9d154f5dbae18b44?s=25&f=y) |
| rating | `r` | g | This property allows users to self-rate their images so that they can indicate if an image is appropriate for a certain audience.
you can 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. |

### License

> [MIT](https://github.com/xn-02f/gravatar/blob/main/LICENSE)