]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix image DecodeConfig regression of WebP images from file cache
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 29 Jan 2026 21:53:13 +0000 (22:53 +0100)
committerGitHub <noreply@github.com>
Thu, 29 Jan 2026 21:53:13 +0000 (22:53 +0100)
Fixes #14453

resources/image.go
resources/image_cache.go
resources/images/images_integration_test.go

index b792c2f1cc0e4dc817d9b739f5b21c976c042a9a..ec69a52869bbb1546a2bc7909d0e1e4984ea0ae4 100644 (file)
@@ -58,7 +58,7 @@ type imageResource struct {
        // original (first).
        root *imageResource
 
-       // These are only set for the root imageResource.
+       // These are only set for the root imageResource.
        exifInfoFn func() (*meta.ExifInfo, error)
        metaInfoFn func() (*meta.MetaInfo, error)
 
index ba0035b2cda69f4fa875300a62827afe6ff09bb7..4a33a0f230dae65eb156bdbce43ccc4c1f0253cb 100644 (file)
@@ -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
index fade5ae3eed38ef1c397c481bf50bee3992229ce..6dc83816c28347df841d555dce09d7401893d7e4 100644 (file)
@@ -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 --