GithubHelp home page GithubHelp logo

irtyamine / custom-avatar-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maidi29/custom-avatar-generator

0.0 0.0 0.0 1.12 MB

Angular Element (Web Component) that creates a random avatar svg image and lets the user customize it.

JavaScript 7.01% CSS 9.48% HTML 23.60% TypeScript 59.91%

custom-avatar-generator's Introduction

custom-avatar-generator

npm

Angular Element (Web Component) that creates a random avatar svg image and lets the user customize it with endless possible combinations.

If you would like to use this generator as Angular Module inside your Angular Application, checkout this package: https://www.npmjs.com/package/ng-custom-avatar-generator

Demo

Use the generator and see how it will look like at your page or application in this ⚡ Demo

See the code and play with the attributes in this ⚡ JSFiddle

Screenshots & Images

User Interface

Generator UI

Resulting Avatars examples

Example Avatar Example Avatar Example Avatar Example Avatar

Usage

Integrate the package script:

<script type="module" src="https://unpkg.com/[email protected]"></script>

Add the Angular Element with optional attributes to adapt the avatar generator.

<custom-avatar-generator 
  shape="square" 
  enable-background="true" 
  display-download="true" 
  texts='{"everything":"EVERYTHING","allColors":"All colors","background":"Background","skin":"Skin","hair":"Hair","hairStyle":"Hair Style","accessory":"Accessory","clothes":"Clothes","clothing":"Clothing","print":"Print"}'>
<custom-avatar-generator 

On every change the component fires an event with the current svg url, so you can listen to it (and e.g. store it in a variable to save it to your database when the user clicks "save") - or whatever you want to do with the svg.

const el = document.querySelector('custom-avatar-generator');
el.addEventListener('svgUrl', (event) => {
    const mySvgUrl = event.detail;
    console.log(mySvgUrl);
    // do whatever you want here
});

Attributes

All input attributes are optional and have a default. Possible inputs are:

name possible values default description
shape 'sqaure' or 'round' 'round' shape of the avatar image
enable-background 'true' or 'false' 'false' Displays a colored background behind the avatar and lets the user customize the color
enable-face 'true' or 'false' 'false' Displays eyebrows, eyes, nose, mouth, facial hair and glasses and lets the user customize the color and type
display-download 'true' or 'false' 'false' Displays a download button below the controls so the user can save the svg file on their device
texts JSON with all displayed text string. Structure below see JSON below Modify the display texts of the controls
{
    "everything": "EVERYTHING",
    "allColors": "All colors",
    "background": "Background", // optional
    "skin": "Skin",
    "hair": "Hair",
    "hairStyle": "Hair Style",
    "accessory": "Accessory",
    "clothes": "Clothes",
    "clothing": "Clothing",
    "print": "Print",
    "eyebrows": "Eyebrows", // optional
    "eyes": "Eyes", // optional
    "nose": "Nose", // optional
    "mouth": "Mouth", // optional
    "facialHair": "FacialHair", // optional
    "glasses": "Glasses" // optional
}

Keep attention that you integrate every property when using the texts attribute because it completely overwrites the default texts object.

Info

Based on https://avataaars.com/

custom-avatar-generator's People

Contributors

maidi29 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.