misc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.alexwennerberg.com/misc
Log | Files | Refs | README | LICENSE

commit 7d9ed202aed7ea3282a2802e4c244f8c91d4554b
parent 96605be9d71c5110c614bb02ae91d0f0f4dd3890
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Mon, 26 Jul 2021 19:55:14 -0700

Add param to output image size

Diffstat:
Mavatar.go | 23+++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/avatar.go b/avatar.go @@ -1,8 +1,8 @@ // Generate a simple avatar based on a hash of your name -// -// Derived from Ted Unangst's Honk +// +// Derived from Ted Unangst's Honk // https://humungus.tedunangst.com/r/honk/v/tip/f/avatar.go -// +// // Copyright (c) 2019 Alex Wennerberg, Ted Unangst <tedu@tedunangst.com> // // Permission to use, copy, modify, and distribute this software for any @@ -21,13 +21,12 @@ package main import ( "bytes" - "fmt" "crypto/sha512" + "fmt" "image" "image/png" - "os" "io/ioutil" - + "os" ) // Modify the four colors used @@ -38,17 +37,21 @@ var avatarcolors = [4][4]byte{ {96, 96, 96, 255}, } +// x and y dimensions in pixels +const size = 500 + func genAvatar(name string) []byte { h := sha512.New() h.Write([]byte(name)) s := h.Sum(nil) // Mess with these numbers to change the size - img := image.NewNRGBA(image.Rect(0, 0, 64, 64)) - for i := 0; i < 64; i++ { - for j := 0; j < 64; j++ { + img := image.NewNRGBA(image.Rect(0, 0, size, size)) + for i := 0; i < size; i++ { + for j := 0; j < size; j++ { p := i*img.Stride + j*4 - xx := i/16*16 + j/16 + xx := i/(size/4)*16 + j/(size/4) x := s[xx] + fmt.Println(x) if x < 64 { img.Pix[p+0] = avatarcolors[0][0] img.Pix[p+1] = avatarcolors[0][1]