Giter VIP home page Giter VIP logo

randomavatar's Introduction

Random Avatar

A tiny script for generating attractive random avatars. Relies on randomColor and the canvas element. Better than those weird Gravatar shapes, more exciting than a solid color. See index.html for some samples.

Demo

Only built to be used in the browser. Never tested with nodejs, but it's wrapped in a UMD pattern. To use it:

var avatar = randomAvatar(); // an image element for easy display
var div = document.getElementById('a-random-element'); // grab some element that's on your website
div.appendChild(avatar); // place it in the DOM

Options

size - All generated avatars are square, so this value is used for both width and height [default: 128]

style - Which of the three background styles to use: circle, square, hex [default: random]

text - The text to display [default: one random capitalized letter]

contrast - Adjusts the contrast of the background colors, with higher values providing a lot more color variations. Values too high will make the text difficult to read, recommended values are 0-40) [default: 25]

luminosity - Directly passed to randomColorjs, controls the luminosity of the generated color. You can specify a string containing random, bright, light or dark [default: bright]

outputType - Which data type to return. If image is specified it will return an Image element. Otherwise, canvas will return the raw canvas element [default: image]

Examples

// returns a 128x128 Image element with a square tile background in a lovely springtime pastel hue and the text "CB" overlaying it
randomAvatar({
	size: 128,
	luminosity: 'light',
	style: 'square',
	text: 'CB'
})

// returns a 32x32 Image element with a random background pattern and no text
randomAvatar({
	size: 32,
	text: ''
})

randomavatar's People

Contributors

vonwolfehaus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.