All Projects → joaner → Namedavatar

joaner / Namedavatar

SVG Avatar generated by name text

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Namedavatar

Dom To Svg
Library to convert a given HTML DOM node into an accessible SVG "screenshot".
Stars: ✭ 67 (-11.84%)
Mutual labels:  svg
React Bootstrap Icons
React component for Bootstrap Icons
Stars: ✭ 71 (-6.58%)
Mutual labels:  svg
Blade Icons
A package to easily make use of SVG icons in your Laravel Blade views.
Stars: ✭ 1,181 (+1453.95%)
Mutual labels:  svg
Pasition
Path Transition with little JS code, render to anywhere - 轻量级 Path 过渡库,渲染到任何地方
Stars: ✭ 1,149 (+1411.84%)
Mutual labels:  svg
Svgeez
A Ruby gem for automatically generating an SVG sprite from a folder of SVG icons.
Stars: ✭ 69 (-9.21%)
Mutual labels:  svg
Svgsprit.es
Public endpoint to generate SVG Sprites
Stars: ✭ 73 (-3.95%)
Mutual labels:  svg
Reaviz
📊 Data visualization library for React based on D3
Stars: ✭ 1,141 (+1401.32%)
Mutual labels:  svg
Personal Goals
List of books I've read, projects I've done, videos I've seen, articles I've read or podcasts I've listened to.
Stars: ✭ 75 (-1.32%)
Mutual labels:  svg
Svgnet
Fork of the SVG library for .NET that makes a GdiGraphics that "draws" on a SVG model
Stars: ✭ 69 (-9.21%)
Mutual labels:  svg
Svg Fill Loader
DEPRECATED, use https://github.com/kisenka/svg-mixer/tree/master/packages/svg-transform-loader instead
Stars: ✭ 74 (-2.63%)
Mutual labels:  svg
H2d2 Shopicons
Essentials E-Commerce icon pack for free.
Stars: ✭ 67 (-11.84%)
Mutual labels:  svg
Muze
Composable data visualisation library for web with a data-first approach now powered by WebAssembly
Stars: ✭ 1,153 (+1417.11%)
Mutual labels:  svg
Sozi
A "zooming" presentation editor
Stars: ✭ 1,185 (+1459.21%)
Mutual labels:  svg
Php Svg Lib
SVG file parsing / rendering library
Stars: ✭ 1,146 (+1407.89%)
Mutual labels:  svg
Nivo
nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries
Stars: ✭ 9,550 (+12465.79%)
Mutual labels:  svg
Zdog
Flat, round, designer-friendly pseudo-3D engine for canvas & SVG
Stars: ✭ 8,904 (+11615.79%)
Mutual labels:  svg
Maker.js
📐⚙ 2D vector line drawing and shape modeling for CNC and laser cutters.
Stars: ✭ 1,185 (+1459.21%)
Mutual labels:  svg
Iconify Sketch
Sketch plug-in for importing over 70,000 icons from 80+ icon sets, including Material Design Icons, FontAwesome, Jam Icons, Open Emoji and many others.
Stars: ✭ 76 (+0%)
Mutual labels:  svg
Svg Loaders React
React adaptation of the SVG Loaders library by Sam Herbert
Stars: ✭ 75 (-1.32%)
Mutual labels:  svg
Cl Aristid
Draw Lindenmayer Systems with Common LISP!
Stars: ✭ 74 (-2.63%)
Mutual labels:  svg

named avatar

Avatar generated by name text based on svg. Fill <svg> as data uri into the <img> src, no added element.

如果用户没有个性头像,就填充用户名生成的<svg>头像。 程序会在 <img src> 上填充data URI,没有额外添加元素。

demo

Installtion

npm install namedavatar --save

Usage

namedavatar is a UMD module, support Browser, Requirejs, Vue2 directive, miniprogram(小程序).

Browser

online example

NOTE that the <img> width and border-radius: 100% requires you additional settings, the program is not set.

<img id="avatar1" src="./invalid.jpg" alt="Tom Hanks" width="40" style="border-radius: 100%">

<script src="/dist/namedavatar.min.js"></script>
<!-- also support requirejs
<script>
requirejs.config({
  paths: {
    namedavatar: '/dist/namedavatar'
  }
})
requirejs('namedavatar', function(namedavatar){
  // ...
})
</script>
-->
<script>
namedavatar.config({
  nameType: 'initials'
})

// fill single <img>
var img = document.getElementById('avatar1')
namedavatar.setImg(img, img.alt)

// fill multi <img>
var imgs = document.querySelectorAll('img[data-name]')
namedavatar.setImgs(imgs, 'data-name')
</script>

if img.src invalid, img#avatar1 will be:

<img id="avatar1" src="data:image/svg+xml,&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;32&quot; height=&quot;32&quot;&gt;&lt;rect fill=&quot;#9C27B0&quot; x=&quot;0&quot; y=&quot;0&quot; width=&quot;100%&quot; height=&quot;100%&quot;&gt;&lt;/rect&gt;&lt;text fill=&quot;#FFF&quot; x=&quot;50%&quot; y=&quot;50%&quot; text-anchor=&quot;middle&quot; alignment-baseline=&quot;central&quot; font-size=&quot;16&quot; font-family=&quot;Verdana, Geneva, sans-serif&quot;&gt;Hanks&lt;/text&gt;&lt;/svg&gt;">

without DOM

support like miniprogram(小程序)

import namedavatar from 'namedavatar'

// create svg html string without DOM
const svg = namedavatar.getSVGString('李连杰')
const uri = namedavatar.getDataURI(svg)
console.log(uri)
// data:image/svg+xml,%3Csvg%20...

Vue2

online example main.js

import { directive } from 'namedavatar/vue'
// register v-avatar="Tom Hanks", show firstName (default)
Vue.directive('avatar', directive);

// or set options and same as above
import namedavatarVue from 'namedavatar/vue'
// register v-avatar="Tom Hanks", show lastName
Vue.use(namedavatarVue, {
    nameType: 'lastName'
})

in vue template

<template>
  <img v-avatar="'Tom Hanks'" width="36"/>
</template>

API

.config(Object options)

filed type default description
nameType string 'firstName' pick from: firstName, lastName, initials
fontFamily string 'Verdana, Geneva, sans-serif' font family
backgroundColors Array Material Design colors *-500 random background color list
textColor string '#FFF' name text color
minFontSize number 8 min font size limit
maxFontSize number 16 max font size limit

.getSVG(string name, Object options)

  • name the full name value
  • options extended options

return <svg> node, get string by svg.outerHTML

.getSVGString(string name, Object options)

added at 1.1.0 version, special for without DOM like miniprogram(小程序)

  • name the full name value
  • options extended options

return <svg> html string

.setImg(HTMLImageElement img, string name)

  • img <img> item
  • name the full name value

create svg by name, and fill to <img src="data:image/svg+xml,<svg>...">

.setImgs(HTMLImageElement[] imgs, string attr)

  • imgs <img> list
  • attr pick full name value from special attr, eg 'alt', 'data-name'

create svg by attr value, batch processing setImg()

.getDataURI(string html)

  • html <svg> node html string

get data uri (rfc2397) of svg html

Contributing

  • IE > 8 (based on svg)
  • Continuous improvement, welcome review and suggest

development

npm install -g watchify
npm run dev

build assert

npm install -g browserify uglifyjs

# build UMD bundle and minify
npm run build && npm run minify

# build for vue
npm run build:vue

unit test:

npm install -g mocha
npm run test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].