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 🙏

© 2026 – Pkg Stats / Ryan Hefner

material-avatar

v0.3.5

Published

simple material design avatars using canvas

Readme

Simple material design avatars using canvas

Enhanced by BrowserStack

Code Climate License 1.33kb gziped!

====

Material-Avatar is non-opinionated and only has a few small features. It was built to solve a larger problem. How can I generate a good looking default avatar for a user?.

I got asked this question once, and there are a lot of other more complex implimentations out there, using bits and bobs to calculate a pixelated image, or grab sets of images from places, or use other web services. I like the way google approached the problem, creating a simple image with initials text.

Material-Avatar uses HTML5 Canvas to fill an element with a random(ized) background color, which uses this great module to find nice random colors, but has a fall-back just incase you don't include it.

Now Supports jQuery!

Useage

  1. Install using npm, bower, or download.

    npm install --save material-avatar
    bower install --save material-avatar

    And include your scripts,

    <script src="vendor/material-avatar/material-avatar.min.js"></script>
  2. Create a nice div and fill it with a name, or use the attribute data-name. Note, material-avatar defaults to using the size provided by the style of the element on the page

    <div class="default-profile-photo" style="height:200px; width:200px;">
      Paul Gilbert
    </div>
  3. Call MaterialAvatar in somewhere on your page.

    <script>
      MaterialAvatar(document.getElementsByClass('default-profile-photo'), options);
    
      //or use jQuery
    
      $('.default-profile-photo').materialAvatar(options);
    </script>
  4. Profit.

Options

EffectName: "default" (type) Description

  1. shape "square" (string) Can either be "circle" or "square", and will take that shape (more shapes in future updates!)

  2. randomColor (object) Settings for using the randomColor library

  3. backgroundColor (string) A hex string for a background color (i.e. '#f12a27'). If not set, one will be chosen at random, or from a default colorPalette (which can be overridden)

  4. textColor (string) A hex string for the text color (i.e. '#fff'). If not set, an accessable friendly color will be chosen based on the background color (either '#222' or '#fff')

  5. colorPalette (array) An array of color hexes that can will be chosen from randomly as a fallback. Defaults can be found in the material-avatar.js file.

  6. fontSize (number or function) An overriding size for font. This can either be a number, measured in px, or a function. If its a function, it will be sent two arguments, the height of the canvas, and the initials length, which can be used to return a calculated font size.

  7. fontFamily "Arial" (string) The chosen font family for generating the canvas initials font.

  8. initials (string) A string of characters used as the initials for the avatar.

  9. name (string) In addition to being able to use the data-name attribute, or the innerHtml of an element, you can also pass a name in the options, which will be broken down into the initial.

see sample or the live website for some examples.

Development

If you'd like to develop this little module a bit further, I use a nice gulp build process.

Get a localhost live-reload web-server running to develop the module

npm install
gulp serve

Before you push your changes, make sure to run the gulp build script

gulp build

License

MIT