adorable

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2019 License: MIT Imports: 14 Imported by: 2

README

go-adorable - Adorable Avatars from Go

The go-adorable project is a Go clone of Adorable Avatars, an image generator for user friendly placeholder avatars. This project's goal is to enable quickly onboarding users into social networks and providing a human centric starting experience.

random

Usage

The library's Go API is extremely simplistic, consisting of a handful of methods that can generate png images according to a few rules. The simplest is to just request a fully random image, which can generate 576 unique faces on a "limitless" background color palette.

avatar := adorable.Random()

if err := ioutil.WriteFile("avatar.png", avatar, 0600); err != nil {
  panic(err)
}
Determinism

Fully random images are useful for most purposes, but sometimes it may be desirable to assign a deterministic image to a specific user. This can be particularly handy for insta-onboarding or as a placeholder if no avatar is set.

avatar := adorable.PseudoRandom([]byte("unique-user-id"))

if err := ioutil.WriteFile("avatar.png", avatar, 0600); err != nil {
  panic(err)
}

pseudorandom

The deterministic avatars may be further restricted to a specific background palette, enabling finer tuned placeholders for default images (e.g. grayscale or other neutral colors). Note, that the images below are the same deterministic ones as above, just with fixed colors.

scheme := color.RGBA{R: 96, G: 128, B: 192, A: 255}
avatar := adorable.PseudoRandomWithColor([]byte("unique-user-id"), scheme)

if err := ioutil.WriteFile("avatar.png", avatar, 0600); err != nil {
  panic(err)
}

colored

Demo

The repository also contains a small demo which lists a few hundred avatars created with different invocation rules. It should be a good staring point if you get stuck or want to play around with the generator and quickly see a summary of the results. You can run it via:

$ go run ./samples.go

Credits

This repository is maintained by Péter Szilágyi (@karalabe), but authorship of the images belongs to the original avatars-api-middleware project and its artists, Kelly Rauwerdink (@missingdink) and Kevin Altman (@itsthatguy).

License

Same as original, MIT.

Documentation

Overview

Package adorable generates (pseudo) random user avatars.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PseudoRandom

func PseudoRandom(seed []byte) []byte

Random creates a brand new deterministic random avatar based on the provided seed and returns it in PNG format.

func PseudoRandomWithColor

func PseudoRandomWithColor(seed []byte, color color.RGBA) []byte

PseudoRandomWithColor creates a brand new deterministic random avatar based on the provided seed using a predefined background color and returns it in PNG format.

func Random

func Random() []byte

Random creates a brand new random avatar and returns it in PNG format.

func RandomWithColor

func RandomWithColor(color color.RGBA) []byte

RandomWithColor creates a brand new random avatar using a predefined background color and returns it in PNG format.

Types

This section is empty.

Directories

Path Synopsis
internal
bodyparts
Package bodyparts contains the avatar body parts.
Package bodyparts contains the avatar body parts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL