Comments (7)
You could use https://avatars.dicebear.com. Support for avatars has been added recently.
from avataaars.
You can also use DiceBear Avatars without HTTP API / Web Request. You just have to install the NPM packages.
See: https://github.com/DiceBear/avatars/tree/v4/packages/avatars-avataaars-sprites#npm
from avataaars.
Hey @stevenleeg, thanks for the feedback, I think that's a good idea. However, unfortunately I don't have bandwidth to do this for now. If you can open a new PR for it, I am happy to review it.
from avataaars.
Hey,
I needed something like this.
Here's my implementation:
import React from 'react'
import Avatar from 'avataaars'
const Avataaar = props => (
<Avatar
avatarStyle='Circle'
{...props}
/>
)
export const SeededAvataaar = ({seed}) => {
const items = seed.match(/.{1,2}/g).map(e => parseInt(e, 16))
const options = { }
const keys = [...configsKeys]
keys.map((e, i) => Object.assign(options, {[e]: configs[e][items[i] % configs[e].length]}))
return (
<Avataaar {...options} />
)
}
const configs = {
topType: [
'NoHair',
'Eyepatch',
'Hat',
'Hijab',
'Turban',
'WinterHat1',
'WinterHat2',
'WinterHat3',
'WinterHat4',
'LongHairBigHair',
'LongHairBob',
'LongHairBun',
'LongHairCurly',
'LongHairCurvy',
'LongHairDreads',
'LongHairFrida',
'LongHairFro',
'LongHairFroBand',
'LongHairNotTooLong',
'LongHairShavedSides',
'LongHairMiaWallace',
'LongHairStraight',
'LongHairStraight2',
'LongHairStraightStrand',
'ShortHairDreads01',
'ShortHairDreads02'
],
accessoriesType: [
'Blank',
'Kurt',
'Prescription01',
'Prescription02',
'Round',
'Sunglasses',
'Wayfarers'
],
hatColor: [
'Black',
'Blue01',
'Blue02',
'Blue03',
'Gray01',
'Gray02',
'Heather',
'PastelBlue',
'PastelGreen',
'PastelOrange',
'PastelRed',
'PastelYellow',
'Pink',
'Red',
'White'
],
hairColor: [
'Auburn',
'Black',
'Blonde',
'BlondeGolden',
'Brown',
'BrownDark',
'PastelPink',
'Platinum',
'Red',
'SilverGray'
],
facialHairType: [
'Blank',
'BeardMedium',
'BeardLight',
'BeardMajestic',
'MoustacheFancy',
'MoustacheMagnum'
],
facialHairColor: [
'Auburn',
'Black',
'Blonde',
'BlondeGolden',
'Brown',
'BrownDark',
'Platinum',
'Red'
],
clotheType: [
'BlazerShirt',
'BlazerSweater',
'CollarSweater',
'GraphicShirt',
'Hoodie',
'Overall',
'ShirtCrewNeck',
'ShirtScoopNeck',
'ShirtVNeck'
],
clotheColor: [
'Black',
'Blue01',
'Blue02',
'Blue03',
'Gray01',
'Gray02',
'Heather',
'PastelBlue',
'PastelGreen',
'PastelOrange',
'PastelRed',
'PastelYellow',
'Pink',
'Red',
'White'
],
graphicType: [
'Bat',
'Cumbia',
'Deer',
'Diamond',
'Hola',
'Pizza',
'Resist',
'Selena',
'Bear',
'SkullOutline',
'Skull'
],
eyeType: [
'Close',
'Cry',
'Default',
'Dizzy',
'EyeRoll',
'Happy',
'Hearts',
'Side',
'Squint',
'Surprised',
'Wink',
'WinkWacky'
],
eyebrowType: [
'Angry',
'AngryNatural',
'Default',
'DefaultNatural',
'FlatNatural',
'RaisedExcited',
'RaisedExcitedNatural',
'SadConcerned',
'SadConcernedNatural',
'UnibrowNatural',
'UpDown',
'UpDownNatural'
],
mouthType: [
'Concerned',
'Default',
'Disbelief',
'Eating',
'Grimace',
'Sad',
'ScreamOpen',
'Serious',
'Smile',
'Tongue',
'Twinkle',
'Vomit'
],
skinColor: [
'Tanned',
'Yellow',
'Pale',
'Light',
'Brown',
'DarkBrown',
'Black'
]
}
const configsKeys = Object.keys(configs)
Note that the seed is expected to be a large hexadecimal string - by large I mean at least 12 pairs of hex characters (see seeded avataaat implementation as to why or how it's used).
from avataaars.
@elis your implementation looks good.
What is exactly your mapping 1 bytes => 1 attribute? I think it would be interesting if empty/blank attributes would show up when a byte is 0x00. What do you think would be the right distribution of the different items. Show every item the same number of times?
PS: Your current implementation shows styles at the beginning of the list more often than the ones at the end, because how you use the modulo "%".
from avataaars.
@FlorianKoerner @fangpenlin @elis
I'd love to have a way to generate an avatar deterministically based on arbitrary id. The problem I see with https://avatars.dicebear.com is that it requires a web request. If I'm rendering 100s of avatars on the same screen, this is really costly.
Is there still interest in a PR to do something like this? (In a client-only fashion).
from avataaars.
Didn't know that, thanks 🙏 .
from avataaars.
Related Issues (20)
- add ref prop to access svg html HOT 1
- Custom shirt and colors
- Usage with require vs import HOT 1
- How to add custom components? HOT 8
- How can I built the dist folder?
- Any suggestions on how to implement this in angular 9? HOT 2
- Is this a react native library? HOT 2
- Uncaught TypeError: Cannot read property 'addStateChangeListener' of undefined HOT 2
- Please update to work with latest React!
- fill-opacity not available on <g> HOT 3
- Warning on componentWillMount HOT 1
- [email protected] requires a peer of react@^16.0.0 but none is installed HOT 1
- Request: support className in addition to style HOT 1
- ranem to UNSAFE_componentWillUpdate HOT 2
- Duplicate id in svg HOT 1
- Can I use this in my react native application? HOT 2
- Legacy context API has been detected within a strict-mode tree & Unsafe life cycle methods HOT 5
- Issue displaying in Firefox HOT 1
- React 18 update HOT 1
- When I update any style the avataaar , got a warning. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avataaars.