Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ameerthehacker/better-default-avatar
Generate avatars with first letter of user's first and last name :camera:
https://github.com/ameerthehacker/better-default-avatar
avatar npm
Last synced: 3 months ago
JSON representation
Generate avatars with first letter of user's first and last name :camera:
- Host: GitHub
- URL: https://github.com/ameerthehacker/better-default-avatar
- Owner: ameerthehacker
- License: mit
- Created: 2018-03-31T13:35:42.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-03T15:39:54.000Z (over 5 years ago)
- Last Synced: 2024-10-04T09:16:27.327Z (3 months ago)
- Topics: avatar, npm
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/better-default-avatar
- Size: 19.5 KB
- Stars: 13
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Better Default Avatar
Generate default avatars based on user's name without a sweat
## How to use :question:
1. Install the library
```sh
npm install named-avatar-generator --save
```2. Start creating avatars
```javascript
const AvatarGenerator = require("named-avatar-generator");AvatarGenerator.generate({ name: "Ameer Jhan", size: 64 }).then(avatar => {
AvatarGenerator.writeAvatar(avatar, "./default-avatar.jpg");
});
```The above code will generate an awesome default avatar as shown below
![Default Avatar](./src/images/default-avatar.jpg)
## Available options
```javascript
AvatarGenerator.generate(options).then(avatar => {
...
});
```| Option | Description | Default |
| ------- | ------------------------------ | ------------------------ |
| name | Full name of the user | No default value |
| size | Size of the avatar in pixels | 40 |
| bgColor | Background color of the avatar | A random beautiful color |
| font | BM font path | Sans with best font size |## Utility Functions
### Write avatar
This can be used to write the image to the filesystem
```javascript
AvatarGenerator.writeAvatar(avatar, path)
.then(() => {
console.log(`Image written to ${path}`);
})
.catch(err => {
console.log(err);
});
```### Get image as Data URI
This can be used to get the image as **data URI**
```javascript
AvatarGenerator.getBase64(avatar, mime)
.then(dataURI => {
console.log(dataURI);
})
.catch(err => {
console.log(err);
});
```### Get image as buffer
This can be used to get the image as buffer
```javascript
AvatarGenerator.getBuffer(avatar, mime)
.then(buffer => {
console.log(buffer);
})
.catch(err => {
console.log(err);
});
```### Available MIME
The supported **MIME** are
* jpeg
* png
* bmp## License
MIT © [Ameer Jhan](mailto:[email protected])