resources/images: Add $image.Colors

Which returns the most dominant colors of an image using a simple histogram method.

Fixes #10307
This commit is contained in:
Bjørn Erik Pedersen
2022-09-21 16:24:54 +02:00
parent 08f0984f91
commit a4028112e3
10 changed files with 90 additions and 0 deletions

View File

@@ -45,6 +45,14 @@ func ReplaceColorInPalette(c color.Color, p color.Palette) {
p[p.Index(c)] = c
}
// ColorToHexString converts a color to a hex string.
func ColorToHexString(c color.Color) string {
r, g, b, a := c.RGBA()
rgba := color.RGBA{uint8(r), uint8(g), uint8(b), uint8(a)}
return fmt.Sprintf("#%.2x%.2x%.2x", rgba.R, rgba.G, rgba.B)
}
func hexStringToColor(s string) (color.Color, error) {
s = strings.TrimPrefix(s, "#")