From 53a95b1d50bd61f241983b96888687ac7489932d Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 24 Feb 2022 18:19:56 +0100 Subject: [PATCH] Preventing index out of range error if increasing block size --- README.adoc | 2 +- idicon.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.adoc b/README.adoc index 6df73f2..305445e 100644 --- a/README.adoc +++ b/README.adoc @@ -10,7 +10,7 @@ HTTP `GET` is used to request an identicon image. curl http://localhost:8000/avatar/23463b99b62a72f26ed677cc556c44e8?s=100&c=v2 .... -Instead of requesting identicons for MD5 hashes of usernames or mail addresses, it is possible to use plain username and mail address. The will result in the same generated identicon. +Instead of requesting identicons for MD5 hashes of usernames or mail addresses, it is possible to use plain username and mail address. This will result in the same generated identicon. Use request query parameter `s` to request images with specified size. Default value is 80px. The size is limited to a maximum value of 512px. diff --git a/idicon.go b/idicon.go index 560a5eb..5ded080 100644 --- a/idicon.go +++ b/idicon.go @@ -40,7 +40,6 @@ func genGhIcon(id string, size int, f func([16]byte) color.RGBA) *image.NRGBA { if size > 512 { size = 512 } - blocks := 5 hash := hashBytes(id) @@ -52,7 +51,7 @@ func genGhIcon(id string, size int, f func([16]byte) color.RGBA) *image.NRGBA { ni := x + blocks*(blocks-y-1) if x+blocks*y > 2*blocks { di := (x + blocks*y) - 2*blocks - data[di] = nibbles[ni]%2 == 0 + data[di] = nibbles[ni%32]%2 == 0 } } }