Skip to content
Initials avatar for golang
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmd/avatar rearrange code structure Nov 19, 2015
Makefile fix ci Aug 9, 2018
avatar.go Set font size for images smaller or larger than 128px Jul 11, 2018
avatar_test.go fix ci Aug 9, 2018


Build Status Coverage Status GoDoc

Generate an avatar image from a user's initials. Image background color depends on name hashes(consistent hashing).

Online Demo

You may switch to heroku-branch to see how to deploy to heroku.


VERSION REQUIRED GO 1.3 or greater

$ go get


Lib Example

import  ""

a := avatar.New("/path/to/fontfile")
b, _ := a.DrawToBytes("David", 128)
// now `b` is image data which you can write to file or http stream.

HTTP Example

// run the http server. The port is :3000 by default. Assumes $GOBIN is in your $PATH.
$ avatar server

// try it on your browser

// to view avaliable options
$ avatar server --help

// Chinese example

HTTP Benchmark


MacBook Pro (Retina, 13-inch, Mid 2014)
Processor: 2.6 GHz Intel Core i5
Memory: 8 GB 1600 MHz DDR3

With logger

$ wrk -t12 -c400 -d30s
Running 30s test @
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    14.18ms   20.56ms 127.10ms   94.18%
    Req/Sec     2.36k     1.34k    5.92k    62.66%
  766657 requests in 30.04s, 1.32GB read
  Socket errors: connect 0, read 150, write 6, timeout 1915
Requests/sec:  25519.86
Transfer/sec:     45.00MB

Without logger

$ wrk -t12 -c400 -d30s
Running 30s test @
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     7.53ms   11.28ms 195.48ms   96.19%
    Req/Sec     3.66k     2.29k   47.47k    75.96%
  1285314 requests in 30.00s, 589.60MB read
  Socket errors: connect 0, read 276, write 0, timeout 1872
  Non-2xx or 3xx responses: 1
Requests/sec:  42849.74
Transfer/sec:     19.66MB

Thanks @lixiaojun for his work.


MIT LICENSE, see LICENSE for details.

You can’t perform that action at this time.