reduce size to 56x56 and add a black border around images

This commit is contained in:
Aaron Bieber 2020-03-10 08:03:03 -06:00
parent b11c100d02
commit b70f21d6c3

View File

@ -15,7 +15,7 @@ type Palette struct {
// Descr describes this plugin
func (h *Palette) Descr() string {
return "Creates an solid 256x56 image of the color specified."
return "Creates an solid 56x56 image of the color specified."
}
// Re is the regex for matching color messages.
@ -44,11 +44,29 @@ func (h *Palette) parseHexColor(s string) (*color.RGBA, error) {
return c, nil
}
func isEdge(x, y int) bool {
if x == 0 || x == 55 {
return true
}
if y == 0 || y == 55 {
return true
}
return false
}
// RespondText to color request events
func (h *Palette) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
const width, height = 256, 56
const width, height = 56, 56
img := image.NewRGBA(image.Rect(0, 0, 256, 56))
img := image.NewRGBA(image.Rect(0, 0, 56, 56))
border := &color.RGBA{
R: 0x00,
G: 0x00,
B: 0x00,
A: 0xff,
}
color, err := h.parseHexColor(post)
if err != nil {
fmt.Println(err)
@ -57,9 +75,13 @@ func (h *Palette) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
if isEdge(x, y) {
img.Set(x, y, border)
} else {
img.Set(x, y, color)
}
}
}
err = SendImage(c, ev.RoomID, img)
if err != nil {