mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-12 20:13:59 +02:00
Add Luminance to Color
To sort an image's colors from darkest to lightest, you can then do: ```handlebars {{ {{ $colorsByLuminance := sort $image.Colors "Luminance" }} ``` This uses the formula defined here: https://www.w3.org/TR/WCAG21/#dfn-relative-luminance Fixes #10450
This commit is contained in:
@@ -67,7 +67,7 @@ type imageResource struct {
|
||||
meta *imageMeta
|
||||
|
||||
dominantColorInit sync.Once
|
||||
dominantColors []string
|
||||
dominantColors []images.Color
|
||||
|
||||
baseResource
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func (i *imageResource) getExif() *exif.ExifInfo {
|
||||
|
||||
// Colors returns a slice of the most dominant colors in an image
|
||||
// using a simple histogram method.
|
||||
func (i *imageResource) Colors() ([]string, error) {
|
||||
func (i *imageResource) Colors() ([]images.Color, error) {
|
||||
var err error
|
||||
i.dominantColorInit.Do(func() {
|
||||
var img image.Image
|
||||
@@ -153,7 +153,7 @@ func (i *imageResource) Colors() ([]string, error) {
|
||||
}
|
||||
colors := color_extractor.ExtractColors(img)
|
||||
for _, c := range colors {
|
||||
i.dominantColors = append(i.dominantColors, images.ColorToHexString(c))
|
||||
i.dominantColors = append(i.dominantColors, images.ColorGoToColor(c))
|
||||
}
|
||||
})
|
||||
return i.dominantColors, nil
|
||||
|
Reference in New Issue
Block a user