-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from tsdtsdtsd/rewrite
Rewrite: Road to v1
- Loading branch information
Showing
24 changed files
with
650 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Tests and Coverage | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 2 | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: '1.13' | ||
- name: Run tests | ||
run: go test -v -race ./... | ||
- name: Run coverage | ||
run: go test -v -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic ./... | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/codecov-action@v3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
GO=go | ||
GOCOVER=$(GO) tool cover | ||
GOTEST=$(GO) test | ||
COVERFILE=coverage.out | ||
|
||
GREEN := $(shell tput -Txterm setaf 2) | ||
YELLOW := $(shell tput -Txterm setaf 3) | ||
WHITE := $(shell tput -Txterm setaf 7) | ||
CYAN := $(shell tput -Txterm setaf 6) | ||
RESET := $(shell tput -Txterm sgr0) | ||
|
||
.PHONY: test test/cover | ||
|
||
all: help | ||
|
||
## Test: | ||
test: ## Run all tests | ||
$(GOTEST) -v -race ./... | ||
|
||
cover: ## Run tests and open coverage in browser | ||
$(GOTEST) -v -coverpkg=./... -covermode=atomic -coverprofile=$(COVERFILE) ./... | ||
$(GOCOVER) -func=$(COVERFILE) | ||
$(GOCOVER) -html=$(COVERFILE) | ||
rm $(COVERFILE) | ||
|
||
## Help: | ||
help: ## Show this help. | ||
@echo '' | ||
@echo 'Usage:' | ||
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}' | ||
@echo '' | ||
@echo 'Targets:' | ||
@awk 'BEGIN {FS = ":.*?## "} { \ | ||
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \ | ||
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \ | ||
}' $(MAKEFILE_LIST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,80 +4,80 @@ | |
![Latest Release Version][shields-version-img] | ||
[![Godoc][godoc-image]][godoc-url] | ||
[![Build Status][travis-image]][travis-url] | ||
![Build Status](https://github.com/tsdtsdtsd/identicon/actions/workflows/ci.yml/badge.svg?branch=rewrite) | ||
[![Go Report Card][grc-image]][grc-url] | ||
[![codecov][codecov-image]][codecov-url] | ||
[![CodeQL](https://github.com/tsdtsdtsd/identicon/actions/workflows/codeql-analysis.yml/badge.svg?branch=master)](https://github.com/tsdtsdtsd/identicon/actions/workflows/codeql-analysis.yml) | ||
|
||
This Go library helps to generate deterministic [Identicons][identicon-wiki] from strings, like these: | ||
This Go library helps to generate deterministic [Identicons][identicon-wiki] from strings. | ||
|
||
![Example Banner](identicon-banner.png "Example Banner") | ||
![Example Banner](_example/bannercreator/identicon-banner.png "Example Banner") | ||
|
||
## Installation | ||
--- | ||
|
||
With module support, you can just import `github.com/tsdtsdtsd/identicon`. | ||
⚠️ I'm working on a complete rewrite for v1.0 ⚠️ | ||
It will definitely break the API and most probably also the internal hashing algorithm, so identicons generated after 1.0 will look different than before. | ||
|
||
--- | ||
|
||
## Usage: | ||
|
||
Get it: | ||
|
||
In other cases you may have to manually: | ||
```sh | ||
go get -u github.com/tsdtsdtsd/identicon | ||
go get github.com/tsdtsdtsd/identicon/v1 | ||
``` | ||
|
||
## Usage example | ||
Create a new identicon: | ||
|
||
Basically, you construct a new `Identicon` type with `identicon.New()`, giving it your identification string and some optional `identicon.Options`. | ||
The resulting struct implements `image.Image` and `draw.Image`, so you can use it flexibly. | ||
```go | ||
red := color.RGBA{255, 0, 0, 255} | ||
|
||
icon, err := identicon.New( | ||
"[email protected]", | ||
// optional: | ||
identicon.WithGridResolution(7), // default: 5 | ||
identicon.WithImageSize(200), // default: 100 | ||
identicon.WithBGColor(red), // default: light gray R:240 G:240 B:240 A:255 (#f0f0f0) | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
``` | ||
|
||
Just import the library and create a new identicon: | ||
`Identicon` implements Go's `image.Image`, so you can use the result directly to encode it as an image file: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"image/png" | ||
"log" | ||
"os" | ||
|
||
"github.com/tsdtsdtsd/identicon" | ||
) | ||
|
||
func main() { | ||
|
||
ic, err := identicon.New( | ||
|
||
// The identicon ID string is mandatory. | ||
// Same string will always result in the same generated identicon. | ||
// Typically this is a username or email address. | ||
"[email protected]", | ||
|
||
// You can define custom options or pass nil for defaults | ||
&identicon.Options{ | ||
BackgroundColor: identicon.RGB(240, 240, 240), | ||
}, | ||
) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Now you are free to use identicon `ic` as any other image.Image or draw.Image interface | ||
fi, _ := os.Create("my-file.png") | ||
png.Encode(fi, ic) | ||
file, err := os.Create("identicon-gary.png") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = png.Encode(file, icon) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
file.Close() | ||
``` | ||
|
||
As it also implements Go's `draw.Image`, you can use it to change the output further: | ||
|
||
```go | ||
// TODO: example | ||
// draw.Draw(icon, ... | ||
``` | ||
|
||
### Banner example | ||
## Banner example | ||
|
||
You can find another example in the `/example` folder. It contains an application, which generates the above image. | ||
It also helps me to test the algorythm for changes. | ||
You can find another example in the /_example folder. It contains an application, which generates the above image. It also helps me to test the algorythm for changes. | ||
|
||
<!-- Markdown link & img dfn's --> | ||
[grc-image]: https://goreportcard.com/badge/github.com/tsdtsdtsd/identicon | ||
[grc-url]: https://goreportcard.com/report/github.com/tsdtsdtsd/identicon | ||
[godoc-image]: https://godoc.org/github.com/tsdtsdtsd/identicon?status.svg | ||
[godoc-url]: https://godoc.org/github.com/tsdtsdtsd/identicon | ||
[travis-image]: https://travis-ci.org/tsdtsdtsd/identicon.svg?branch=master | ||
[travis-url]: https://travis-ci.org/tsdtsdtsd/identicon | ||
[codecov-image]: https://codecov.io/gh/tsdtsdtsd/identicon/branch/master/graph/badge.svg | ||
[codecov-url]: https://codecov.io/gh/tsdtsdtsd/identicon | ||
[godoc-image]: https://pkg.go.dev/badge/github.com/tsdtsdtsd/identicon.svg | ||
[godoc-url]: https://pkg.go.dev/github.com/tsdtsdtsd/identicon | ||
[codecov-image]: https://codecov.io/gh/tsdtsdtsd/identicon/branch/rewrite/graph/badge.svg | ||
[codecov-url]: https://codecov.io/gh/tsdtsdtsd/identicon/tree/rewrite | ||
[shields-version-img]: https://img.shields.io/github/v/release/tsdtsdtsd/identicon | ||
[identicon-wiki]: https://en.wikipedia.org/wiki/Identicon |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
module github.com/tsdtsdtsd/identicon | ||
module github.com/tsdtsdtsd/identicon/v1 | ||
|
||
go 1.11 | ||
go 1.13 | ||
|
||
require ( | ||
github.com/stretchr/testify v1.8.1 | ||
github.com/tsdtsdtsd/identicon v0.3.2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= | ||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= | ||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= | ||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= | ||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= | ||
github.com/tsdtsdtsd/identicon v0.3.2 h1:ABkl45kE2SWHfWZaGvcWG47+LBJ143NFxl6MdlmfjhY= | ||
github.com/tsdtsdtsd/identicon v0.3.2/go.mod h1:rxaWtLmj/xwICNxQJD9c0xVkiBgNfZJKv9vNE+FhqG0= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
Binary file not shown.
Oops, something went wrong.