Skip to content

dicebear-go is an API wrapper for https://dicebear.com. Using the API you can get custom avatars for your projects.

License

Notifications You must be signed in to change notification settings

jvherck/dicebear-go

Repository files navigation

Dicebear-go

dicebear-go is a package that wraps around DiceBear's API. This allows you to easily generate tons of unique avatars in Go. The API can generate more than 1 sexdecillion (that's 17 zeroes!) unique avatars!

dicebear-go version Go Version License Code of Conduct


Other languages

If you want to use Dicebear avatars but don't use Golang, you can use the dicebear Python package or the official JS/TS package.


Table of contents


Useful links


Installation

Install the dicebear-go package using the following command:

go get -u github.com/jvherck/dicebear-go

Basic usage

package main

import (
	"fmt"
	"log"

	"github.com/jvherck/dicebear-go"
)

func main() {
	// Create a new avatar with the "adventurer" style and a random seed
	avatar, err := dicebear.NewAvatar(dicebear.Adventurer, "", nil, nil)
	if err != nil {
		log.Fatalf("Failed to create avatar: %v", err)
	}

	// Get the avatar URL
	fmt.Println("Avatar URL:", avatar.URL())

	// Save the avatar as an SVG file
	outputPath := "avatar.svg"
	_, err = avatar.Save(dicebear.SVG, outputPath, false)
	if err != nil {
		log.Fatalf("Failed to save avatar: %v", err)
	}

	fmt.Println("Avatar saved to:", outputPath)
}

/*
Output:
Avatar URL: https://api.dicebear.com/9.x/adventurer/svg?seed=random-seed
Avatar saved to: avatar.svg
*/

Contributing

We welcome contributions from the community! Whether you're fixing a bug, adding a feature, or improving documentation, your help is appreciated. Find out in our Contributing Guide how to contribute to this project.


Credits

Special thanks to Dicebear (Florian Körner) for making this amazing API and to all artists for creating all the awesome avatars and artwork!

Disclaimer: this repository and its owner are not affiliated with DiceBear.


Licenses and privacy policy