resources/images: Add some mask tests

Closes #13244
This commit is contained in:
Bjørn Erik Pedersen
2025-01-10 09:54:30 +02:00
parent 71fae99189
commit 06cc8673fa
5 changed files with 51 additions and 0 deletions

View File

@@ -133,6 +133,57 @@ Home.
runGolden(t, name, files)
}
func TestGoldenFiltersMask(t *testing.T) {
t.Parallel()
if skipGolden {
t.Skip("Skip golden test on this architecture")
}
// Will be used to generate golden files.
name := "filters_mask"
files := `
-- hugo.toml --
[imaging]
bgColor = '#ebcc34'
hint = 'photo'
quality = 75
resampleFilter = 'Lanczos'
-- assets/sunset.jpg --
sourcefilename: ../testdata/sunset.jpg
-- assets/mask.png --
sourcefilename: ../testdata/mask.png
-- layouts/index.html --
Home.
{{ $sunset := resources.Get "sunset.jpg" }}
{{ $mask := resources.Get "mask.png" }}
{{ template "mask" (dict "name" "transparant.png" "base" $sunset "mask" $mask) }}
{{ template "mask" (dict "name" "yellow.jpg" "base" $sunset "mask" $mask) }}
{{ template "mask" (dict "name" "wide.jpg" "base" $sunset "mask" $mask "spec" "resize 600x200") }}
{{ define "mask"}}
{{ $ext := path.Ext .name }}
{{ if lt (len (path.Ext .name)) 4 }}
{{ errorf "No extension in %q" .name }}
{{ end }}
{{ $format := strings.TrimPrefix "." $ext }}
{{ $spec := .spec | default (printf "resize 300x300 %s" $format) }}
{{ $filters := slice (images.Process $spec) (images.Mask .mask) }}
{{ $name := printf "images/%s" .name }}
{{ $img := .base.Filter $filters }}
{{ with $img | resources.Copy $name }}
{{ .Publish }}
{{ end }}
{{ end }}
`
runGolden(t, name, files)
}
func TestGoldenFiltersText(t *testing.T) {
t.Parallel()

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

BIN
resources/testdata/mask.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB