Git Product home page Git Product logo

initials-avatar's Introduction

initials-avatar

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

https://initials.herokuapp.com

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

Installation

VERSION REQUIRED GO 1.3 or greater

$ go get github.com/holys/initials-avatar/...

Usage

Lib Example

import  "github.com/holys/initials-avatar"

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
// http://127.0.0.1:3000/hello 

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

// Chinese example
http://127.0.0.1:3000/%E5%AD%94

HTTP Benchmark

Environment:

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 http://10.20.142.147:3000/a
Running 30s test @ http://10.20.142.147:3000/a
  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 http://10.20.142.147:3000/a
Running 30s test @ http://10.20.142.147:3000/a
  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.

LICENSE

MIT LICENSE, see LICENSE for details.

initials-avatar's People

Contributors

bryant1410 avatar gernest avatar holys avatar rchunping avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

initials-avatar's Issues

Making the project go gettable

Hey, kudos for the nice work. It will be great if the project was easy to install without the make instructions.

That can be easy if the name of the repository would have to change and remove the dash(-) character. I suggest you name it something like avatar .

That way, gor people who wants to install the command it can just type

go get  -v github.com/holys/avatar/cmd/avatar

And for those who want to install the library can just type

go get  -v github.com/holys/avatar

That is ofcourse after moving the contents of github.com/holys/initials-avatar/avatar to github.com/holys/avatar

Add tests

@holys I am currently working on tests for the avatar package.

If anyone else is working on this maybe we should see what is the best approach. Meanwhile I try to take the path to the font file from the environment variables.

This is how my makefile looks like in the moment.

.PHONY: test

fontFile=$(CURDIR)/resource/fonts/Hiragino_Sans_GB_W3.ttf
all: install

test:
    AVATAR_FONT=$(fontFile) go test -v ./avatar

install:
    go install github.com/holys/initials-avatar/cmd/avatar

Note I had to rename the font file to remove spaces inorder to work in my linux machine.

And the avatar_test.go file

package avatar

import (
    "os"
    "testing"
)

func TestInitialsAvatar_DrawToBytes(t *testing.T) {
    fontFile := os.Getenv("AVATAR_FONT")
    if fontFile == "" {
        t.Skip("Font file is needed")
    }

    av := New(fontFile)

    stuffs := []struct {
        name      string
        size      int
        undersize bool
        oversize  bool
    }{
        {"Swordsmen", 22, true, false},
        {"Condor Heroes", 30, false, false},
        {"Condor Heroes", 30, false, false},
        //      {"Condor Heroes", 200, false, true},
    }

    for _, v := range stuffs {
        _, err := av.DrawToBytes(v.name, v.size)
        if err != nil {
            t.Error(err)
        }
    }
}

Before I do something crazy, any imput will be appreciated. This is due to the fact that the local fuctions will also need tests, and will it we okay to have a test case like TestGetInitials for testing local getInitials function ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.