~ols/avgen

49e6c479e20edfbccf167d9ce49cc7ece79fe8ef — Oliver Leaver-Smith 2 months ago
Initial commit
2 files changed, 30 insertions(+), 0 deletions(-)

A go.mod
A main.go
A  => go.mod +5 -0
@@ 1,5 @@
module avgen

go 1.13

require github.com/ipsn/go-adorable v1.0.0

A  => main.go +25 -0
@@ 1,25 @@
package main

import (
	"bytes"
	"image"
	"image/png"
	"log"
	"net/http"

	adorable "github.com/ipsn/go-adorable"
)

func Handle(w http.ResponseWriter, r *http.Request) {
	seed := r.URL.Query().Get("seed")
	log.Println(seed)
	w.Header().Set("Content-Type", "image/png")
	avatar := adorable.PseudoRandom([]byte(seed))
	img, _, _ := image.Decode(bytes.NewReader(avatar))
	png.Encode(w, img)
}

func main() {
	http.HandleFunc("/", Handle)
	http.ListenAndServe(":1314", nil)
}