From 87d48c905afbe16b15e0fc6f622b8bf22df4187f Mon Sep 17 00:00:00 2001 From: Jan Bessler Date: Tue, 24 Feb 2026 17:34:02 +0100 Subject: [PATCH] Initial commit --- go.mod | 10 +++++++++ go.sum | 6 +++++ main.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ out.png | Bin 0 -> 3829 bytes 4 files changed, 84 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 out.png diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a50a690 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module profile-picture-generator + +go 1.25.0 + +require github.com/fogleman/gg v1.3.0 + +require ( + github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect + golang.org/x/image v0.36.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c37ef61 --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8= +github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= +golang.org/x/image v0.36.0 h1:Iknbfm1afbgtwPTmHnS2gTM/6PPZfH+z2EFuOkSbqwc= +golang.org/x/image v0.36.0/go.mod h1:YsWD2TyyGKiIX1kZlu9QfKIsQ4nAAK9bdgdrIsE7xy4= diff --git a/main.go b/main.go new file mode 100644 index 0000000..7449887 --- /dev/null +++ b/main.go @@ -0,0 +1,68 @@ +package main + +import ( + "crypto/sha1" + "fmt" + "strconv" + + "github.com/fogleman/gg" +) + +// 8x8 square of 100x100 px squares +func main() { + dc := gg.NewContext(800, 800) + + hash := hash("InsightForgeOrg") + + colorString := hash[0:6] + r, g, b := rgbFromHex(colorString) + dc.SetRGB255(r, g, b) + + for i, character := range hash[6:14] { + tmp, _ := strconv.ParseUint(string(character), 16, 8) + n := int(tmp) + for _, v := range []uint{0, 1, 2, 3} { + on := hasBit(n, v) + + dc.DrawRectangle(float64(v * 100), float64(i * 100), 100, 100) + dc.DrawRectangle(700 - float64(v * 100), float64(i * 100), 100, 100) + if !on { + dc.SetRGB255(r, g, b) + } else { + dc.SetRGB255(255, 255, 255) + } + dc.Fill() + } + } + + dc.SavePNG("out.png") +} + +func rgbFromHex(hex string) (int, int, int) { + r, _ := strconv.ParseUint(hex[0:2], 16, 8) + g, _ := strconv.ParseUint(hex[2:4], 16, 8) + b, _ := strconv.ParseUint(hex[4:6], 16, 8) + return int(r), int(g), int(b) +} + +func hash(str string) string { + h := sha1.New() + h.Write([]byte(str)) + res := h.Sum(nil) + return fmt.Sprintf("%x", res) +} + +func hasBit(n int, pos uint) bool { + val := n & (1 << pos) + return (val > 0) +} + +// 9d26bf3cf1fb2b2f02d4a2013333f4fcd551cb2e +// 9d26bf -> color +// 3 -> row1 +// c -> row2 +// ... +// b -> row8 + +// 3 = 0 0 1 1 +// diff --git a/out.png b/out.png new file mode 100644 index 0000000000000000000000000000000000000000..cca0fc2baf888664d21de25b67f567ed45be6286 GIT binary patch literal 3829 zcmeAS@N?(olHy`uVBq!ia0y~yU{(NO4kn;Th|olP1_r)8o-U3d6?5L)IGDS}K*H^! zx&Pt|JfRoEGqg+&cWpWFs845dvDOcTjt42GkOAr%N4zrSEKzIm?nOH1aP(}q=tO!jEo9pt_DobCPR zb?-hmkH+fIP0`i0^?!TrF))14sN2B6ki^8zprAI&7}=Kj3E~YH>$rd%*%}L1GRBM1um?OJ6eAZs@a74feU9c&%9QHpbn* w!Tv127=wdP0wco_mQlu#3xqeoqW1s)oifHY?7#oD0lTvdp00i_>zopr00S7*mH+?% literal 0 HcmV?d00001