From b5d43cdc1783796d9c6b17c7e135fa46d8b0279d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 29 Jan 2026 22:53:13 +0100 Subject: [PATCH] Fix image DecodeConfig regression of WebP images from file cache Fixes #14453 --- resources/image.go | 2 +- resources/image_cache.go | 1 + resources/images/images_integration_test.go | 23 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/resources/image.go b/resources/image.go index b792c2f1c..ec69a5286 100644 --- a/resources/image.go +++ b/resources/image.go @@ -58,7 +58,7 @@ type imageResource struct { // original (first). root *imageResource - // These are only set for the root imageResource. + // These 2 are only set for the root imageResource. exifInfoFn func() (*meta.ExifInfo, error) metaInfoFn func() (*meta.MetaInfo, error) diff --git a/resources/image_cache.go b/resources/image_cache.go index ba0035b2c..4a33a0f23 100644 --- a/resources/image_cache.go +++ b/resources/image_cache.go @@ -66,6 +66,7 @@ func (c *ImageCache) getOrCreate( }) img.setSourceFilenameIsHash(true) img.setMediaType(conf.TargetFormat.MediaType()) + img.Format = conf.TargetFormat if err := img.InitConfig(r); err != nil { return err diff --git a/resources/images/images_integration_test.go b/resources/images/images_integration_test.go index fade5ae3e..6dc83816c 100644 --- a/resources/images/images_integration_test.go +++ b/resources/images/images_integration_test.go @@ -51,6 +51,29 @@ Orientation: {{ $orientation }}|eq 6: {{ eq $orientation 6 }}|Type: {{ printf "% b.AssertFileContent("public/index.html", "Orientation: 6|eq 6: true|") } +func TestColorsIssue14453(t *testing.T) { + files := ` +-- hugo.toml -- +-- assets/sunset.jpg -- +sourcefilename: ../testdata/sunset.jpg +-- layouts/home.html -- +{{ $img := resources.Get "sunset.jpg" }} +{{ $img := $img.Fit "100x100" }} +{{ $img := $img.Filter (slice images.AutoOrient (images.Process "fit 100x100 webp")) -}} +{{ $colors := $img.Colors }} +Colors: {{ $colors }}| +` + tempDir := t.TempDir() + for range 2 { + b := hugolib.Test(t, files, hugolib.TestOptWithConfig(func(cfg *hugolib.IntegrationTestConfig) { + cfg.NeedsOsFS = true + cfg.WorkingDir = tempDir + })) + b.AssertFileContent("public/index.html", "Colors: [#2e2f34 #a39e94 #d39e57 #a96b3a #747b84 #7c838a]|") + + } +} + func BenchmarkImageResize(b *testing.B) { files := ` -- content/p1/sunrise.jpg -- -- 2.39.5