named-avatar-generator
Generate avatars with first letter of user's first and last name
Last updated 2 years ago by ameerthehacker .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install named-avatar-generator 
SYNC missed versions from official npm registry.

Named Avatar Generator

Generate default avatars based on user's name without a sweat

How to use :question:

  1. Install the library
npm install named-avatar-generator --save
  1. Start creating avatars
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

Available options

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

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

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

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

Current Tags

  • 0.0.1                                ...           latest (2 years ago)

1 Versions

  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 2
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |