Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
github.com/gomig/avatar
Advanced customizable svg avatar generator for golang.
Unicode | Letter | Sticker | Female | Female | Female | Male | Male | Male |
---|---|---|---|---|---|---|---|---|
go get github.com/gomig/avatar
If letter shape or letter map not founded for first character of string fallback (Default
) letter shape will be used.
import "github.com/gomig/avatar"
func main(){
john := avatar.NewTextAvatar("John") // make avatar with J letter
htmlTag := john.InlineSVG()
svg := john.SVG()
dataImg := john.Base64()
john.SaveAs("john.svg")
}
import "github.com/gomig/avatar"
func main(){
// Register sticker shape globally
avatar.AddSticker("apple", `<path fill="{text}" d="..."/>`)
// Create avatar using apple sticker
apple := avatar.NewStickerAvatar("apple")
apple.SaveAs("apple.svg")
}
import "github.com/gomig/avatar"
func main(){
mia := avatar.NewPersonAvatar(false) // pass true for male, false for female
mia.RandomizeShape(avatar.Circle, "polygon") // get random background shape
mia.SaveAs("mia.svg")
}
Generate svg content for embeded (html svg tag) element.
Get svg file content.
Get svg as base64 data image.
Save svg file.
Get avatar type.
Get avatar shape.
Get avatar palette.
Get avatar letter.
Get avatar letter unicode.
Get avatar sticker name.
You can pass list off registered parts to generate random avatar. If no parameters passed random character created from all registered values.
Note: in PersonAvatar random values get from registered value based on gender.
If you want use predefined elements you can access them by constant.
#3a292f
hair color.#744819
hair color.#432818
hair color.#fbdad0
skin color.#ceaa82
skin color.#b06f51
skin color.RegisterExtraPalettes
called)RegisterExtraPalettes
called)RegisterExtraPalettes
called)RegisterExtraPalettes
called)RegisterExtraPalettes
called)RegisterExtraPalettes
called)RegisterExtraPalettes
called)RegisterExtraPalettes
called)RegisterExtraMaleHair|RegisterExtraFemaleHair
called)RegisterExtraMaleHair|RegisterExtraFemaleHair
called)RegisterExtraMaleHair
called)RegisterExtraFemaleHair
called)RegisterExtraMaleDress|RegisterExtraFemaleDress
called)RegisterExtraMaleDress|RegisterExtraFemaleDress
called)RegisterExtraMaleDress|RegisterExtraFemaleDress
called)RegisterExtraFacialHair
called)RegisterExtraFacialHair
called)RegisterExtraFacialHair
called)RegisterExtraFacialHair
called)RegisterExtraFacialHair
called)RegisterExtraMaleGlass|RegisterExtraFemaleGlass
called)RegisterExtraMaleGlass|RegisterExtraFemaleGlass
called)RegisterExtraMaleGlass|RegisterExtraFemaleGlass
called)RegisterExtraMaleGlass|RegisterExtraFemaleGlass
called)RegisterExtraFemaleAccessory
called)RegisterExtraFemaleAccessory
called)Randomize shape from registered ones.
Randomize avatar color palette from registered ones.
Randomize sticker from registered ones (this method works on sticker avatar only).
Randomize skin from registered ones (this method works on person avatar only).
Randomize hair color from registered ones (this method works on person avatar only).
Randomize facial hair from registered ones (this method works on male person avatar only).
Randomize hair from registered ones (this method works on person avatar only).
Randomize dress from registered ones (this method works on person avatar only).
Randomize eye from registered ones (this method works on person avatar only).
Randomize eyebrow from registered ones (this method works on person avatar only).
Randomize mouth from registered ones (this method works on person avatar only).
Randomize glass from registered ones (this method works on person avatar only).
Randomize accessory from registered ones (this method works on person avatar only).
By default no extra element are exists and all generated avatar are equal! for using predefined package element you must call register functions.
Register extra color palettes (purple
, green
, blue
, yellow
, orange
, red
, teal
and pink
).
Register transform map for transforming persian letter to english.
Register letter shape for persian letters (if RegisterPersianTransform
called this method not work and persian letter transformed and shown as english letter)
Register extra male hairs (short
, medium
and wavy
).
Register extra male dresses (t-shirt
, suit
and shirt
).
Register extra male facial hairs (mustach
, mustach-fancy
, beard
, beard-medium
and beard-long
).
Register extra male glasses (prescription
, prescription-round
, sunglass
and sunglass-round
).
Currently no male accessory are designed built-in!
Register extra female hairs (short
, wavy
and curly
).
Register extra female dresses (t-shirt
, suit
and shirt
).
Register extra female glasses (prescription
, prescription-round
, sunglass
and sunglass-round
).
Register extra female accessory (necklace
and choker
).
Avatar generation is based on separated svg elements. You can customize current avatar style or add new styles to avatar package using helpers method.
You can work on template.ai file and save your work to svg then add your generated elements parts to avatar packages. Each shape must have some placeholder for replace colors or id in final result.
Elements color are based on palette. Color value can be simple hex (Hex
) or gradient (Definition
).
There are three type of colors:
Caution: for gradient colors, gradient element must contains id="{id}"
placeholder attribute. otherwise color not work!
Clear all registered hair color and set hair colors to pre-defined (Default
, brown
, light_brown
and dark_brown
) value.
Add new hair color.
import "github.com/gomig/avatar"
func main(){
avatar.AddHairColor(
"brown",
avatar.Color{avatar.Hex, "#432818"},
avatar.Color{avatar.Hex, "#140b06"},
avatar.Color{avatar.Hex, "#884139"},
)
}
Change default hair color.
Clear all registered skin color and set skin colors to pre-defined (Default
, white
, brown
and black
) value.
Add new skin color.
import "github.com/gomig/avatar"
func main(){
avatar.AddHairColor(
"blond",
avatar.Color{
avatar.Definition,
`<linearGradient id="{id}" gradientTransform="rotate(90)">
<stop offset="5%" stop-color="#fffa00" />
<stop offset="95%" stop-color="#cc8800" />
</linearGradient>`,
},
avatar.Color{avatar.Hex, "#84706d"})
}
Change default skin color.
Clear all registered palette and keep Default
palette only.
Add new palette.
import "github.com/gomig/avatar"
func main(){
avatar.AddPalette(
"blue",
avatar.Color{avatar.Hex, "#a2cced"},
avatar.Color{avatar.Hex, "#162835"},
avatar.Color{avatar.Hex, "#006fc8"},
avatar.Color{avatar.Hex, "#045389"},
avatar.Color{avatar.Hex, "#121b21"},
)
}
Change default palette.
You can use following placeholder in your element to replace with dynamic generated data in avatar.
{id}
must included in gradient colors to pass dynamic id.{skin}
person skin color (used in body shape).{skin_shadow}
dark skin color (used in shadow parts of body shape).{hair}
hair color (used in hair, eyebrow and facialHair).{hair_shadow}
dark parts of hair (used in hair, eyebrow and facialHair).{hair_highlight}
highlight parts of hair (used in hair, eyebrow and facialHair).{shape}
background shape color (used in background shape fill).{text}
text and sticker color.{dress}
main dress color.{dress_shadow}
darken parts color of dress.{decorator}
decorator color (tie, glass frame, necklace, etc.).Note: You can set mask for each background shape. mask shape must has white
fill.
Clear all registered shapes.
Register new background shape.
import "github.com/gomig/avatar"
func main(){
avatar.AddShape(
"circle",
"<circle fill="{shape}" cx="64" cy="64" r="64"/>",
"<path fill="white" d="M0,0v64c0,35.3,28.7,64,64,64s64-28.7,64-64V0H0z"/>")
}
You can register shape for each unicode letters or you can transform letters to english.
Define new unicode letter for transform to english letter or letter with shape.
import "github.com/gomig/avatar"
func main(){
avatar.AddLetterMap("ج", `j`)
}
Define shape for letter. Letter must have one character length! By default english letter shapes are registered but you can override them by re-set letter shape.
import "github.com/gomig/avatar"
func main(){
avatar.AddLetterShape("a", `<path fill="{text}" d="..."/>`)
}
Set fallback default letter shape. If no shape or transform for character found this shape used!
Clear all registered stickers.
import "github.com/gomig/avatar"
func main(){
avatar.ResetSticker()
}
Register new sticker.
import "github.com/gomig/avatar"
func main(){
avatar.AddSticker("star", `<path fill="{text}" d="..."/>`)
}
Person avatar can be male or female. all type of data can registered for Male
, Female
or Both
.
Set character body shape to default.
Set character body shape.
import "github.com/gomig/avatar"
func main(){
avatar.SetBody(`<path fill="{skin}" ...>`)
}
Clear all registered facial hairs.
Add new facial hair.
import "github.com/gomig/avatar"
func main(){
avatar.SetBody("wavy", `<path fill="{hair}" ...>`)
}
Clear all registered male hairs (except Default
).
Clear all registered female hairs (except Default
).
Register new hair style.
import "github.com/gomig/avatar"
func main(){
avatar.SetBody("wavy", avatar.Male, `<path fill="{hair}" ...>`)
}
Set default hair.
Clear all registered male dresses (except Default
).
Clear all registered female dresses (except Default
).
Register new dress.
import "github.com/gomig/avatar"
func main(){
avatar.AddCloth(
"polo",
avatar.Both,
`<g>
<path fill="{dress}" ...>
<path fill="{dress_shadow}" ...>
</g>`,
)
}
Set default dress shape.
Clear all registered male eye (except Default
).
Clear all registered female eye (except Default
).
Register new eye.
import "github.com/gomig/avatar"
func main(){
avatar.SetBody("asian", avatar.Male, `<path ...>`)
}
Set default eye shpae.
Clear all registered male eyebrow (except Default
).
Clear all registered female eyebrow (except Default
).
Register new eyebrow.
import "github.com/gomig/avatar"
func main(){
avatar.SetBody("wavy", avatar.Male, `<path fill="{hair_shadow}" ...>`)
}
Set default eyebrow shape.
Clear all registered male mouths (except Default
).
Clear all registered female mouths (except Default
).
Register new mouth.
import "github.com/gomig/avatar"
func main(){
avatar.AddMouth("red_lip", avatar.Female, `<path ...>`)
}
Set default mouth.
Delete all registered male glasses.
Delete all registered female glasses.
Register new glass.
Clear all registered male accessory.
Clear all registered female accessory.
Add new accessory.
import "github.com/gomig/avatar"
func main(){
avatar.SetBody("necklace", avatar.Female, `<path fill="{decorator}" ...>`)
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.