mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
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:
@@ -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, "#")
|
||||
|
||||
|
Reference in New Issue
Block a user