aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources/image.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-04-15 10:09:25 +0200
committerBjørn Erik Pedersen <[email protected]>2024-04-16 10:02:46 +0200
commite197c7b29d8814d098bd53e9e7efd97c70f8de5f (patch)
treeb91bd66bb2eb27d2b1dc07637b66bcdd34951b93 /resources/image.go
parent74e9129568e3b506a34205f11d024400f833a907 (diff)
downloadhugo-e197c7b29d8814d098bd53e9e7efd97c70f8de5f.tar.gz
hugo-e197c7b29d8814d098bd53e9e7efd97c70f8de5f.zip
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
Diffstat (limited to 'resources/image.go')
-rw-r--r--resources/image.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/resources/image.go b/resources/image.go
index 78a57bb53..8f70a665a 100644
--- a/resources/image.go
+++ b/resources/image.go
@@ -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