npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@voicenter/avatars

v1.0.9

Published

Avatars

Downloads

62

Readme

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] [required]:
    • AvatarAccountID [integer] [required]: ID of the Account.
    • AvatarID [integer] [required]: ID of the Avatar.
    • AvatarData [object] [required]:
      • Coordinates : {top, left, width, height } [Object] [required]: 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] [required]: 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] [required]:

    • AvatarAccountID [integer] [required]: ID of the Account.
    • AvatarID [integer] [required]: ID of the Avatar.
    • AvatarData [object] [required]:
      • Hex [string] [required]: hex color of the background
      • TemplateID [integer] [required]: 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] [required]:

    • AvatarAccountID [integer] [required]: ID of the Account.
    • AvatarID [integer] [required]: ID of the Avatar.
    • AvatarData [object] [required]:
      • Hex [string] [required]: hex color of the background
      • Content [string] [required]: Text to be placed on the image
  • Example:

await avatar.generateFromContent({
  AvatarAccountID: 21,
  AvatarID: 4,
  AvatarData: { Content: "SZ", Hex: "#640a82" },
});