Fix image DecodeConfig regression of WebP images from file cache

Fixes #14453
This commit is contained in:
Bjørn Erik Pedersen
2026-01-29 22:53:13 +01:00
committed by GitHub
parent 6ef8017f60
commit b5d43cdc17
3 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -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)
+1
View 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
@@ -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 --