1.0.9 • Published 3 years ago

@voicenter/avatars v1.0.9

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

Avatar Library

A library for uploading and generating avatars.

How to install

npm install @voicenter/avatars;

Importing using ES6 modules:

import { Avatar } from "@voicenter/avatars";

Importing using CommonJS:

const { Avatar } = require("@voicenter/avatars");

How to use

Create an instance of the Avatar class

const avatar = new Avatar(config);

whereconfig is a config object

{
  avatarsPath: string; // path to folder with saved avatars
  templatesPath: string; // path to folder with templates
  sizes?: Array<number>; // sizes of images to save [optional]
}

Example:

{
  avatarsPath: "./src/media",
  templatesPath: "./src/templates"
}

To generate images of custom sizes, add sizes to the config. Default sizes are 168, 32, 24

{
  avatarsPath: "./src/media",
  templatesPath: "./src/templates",
  sizes: [300, 200, 100]        
}

Library methods

Avatar.upload


Uploads the avatar image in sizes provided in config or default sizes (168x168, 32x32 and 24x24).

The images are saved as src/media/<AvatarAccountID>/<AccountID>/<size>.png

  • Arguments
  • inputBody object:
    • AvatarAccountID integer: ID of the Account.
    • AvatarID integer: ID of the Avatar.
    • AvatarData object:
      • Coordinates : {top, left, width, height } Object: Object of coordinates for crop. Check the image below to understand the meaning of the object properties. If you don't want to crop the image, set top: 0, left: 0, width: <width of the image>, height: <height of the image>
      • File string: Base64 encoded image. For test you can convert image to Base64 here: https://www.base64-image.de/

alt text

  • Example:
await avatar.upload({
  AvatarAccountID: 21,
  AvatarID: 3,
  AvatarData: {
    Coordinates: { width: 100, height: 100, left: 20, top: 20 },
    File: "data:image/jpeg;base64,/9j/4AAAABBGQ...",
  },
});

Avatar.generateFromTemplate


Generates the avatar image from present template and saves it in sizes provided in config or default sizes (168x168, 32x32 and 24x24) using the template and background color given in the input object.

The images are saved as src/media/<AvatarAccountID>/<AccountID>/<size>.png

  • Arguments

  • inputBody object:

    • AvatarAccountID integer: ID of the Account.
    • AvatarID integer: ID of the Avatar.
    • AvatarData object:
      • Hex string: hex color of the background
      • TemplateID integer: ID of the template
  • Example:
await avatar.generateFromTemplate({
  AvatarAccountID: 21,
  AvatarID: 2,
  AvatarData: { TemplateID: 1, Hex: "#640a82" },
});

Avatar.generateFromContent


Generates the avatar image with given text and saves it in sizes provided in config or default sizes (168x168, 32x32 and 24x24) using the background color given in the input object.

The images are saved as src/media/<AvatarAccountID>/<AccountID>/<size>.png

  • Arguments

  • inputBody object:

    • AvatarAccountID integer: ID of the Account.
    • AvatarID integer: ID of the Avatar.
    • AvatarData object:
      • Hex string: hex color of the background
      • Content string: Text to be placed on the image
  • Example:
await avatar.generateFromContent({
  AvatarAccountID: 21,
  AvatarID: 4,
  AvatarData: { Content: "SZ", Hex: "#640a82" },
});
1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago