diff --git a/resources/images/images_golden_integration_test.go b/resources/images/images_golden_integration_test.go index 20f3d23f99e..84b1c35ac7a 100644 --- a/resources/images/images_golden_integration_test.go +++ b/resources/images/images_golden_integration_test.go @@ -56,8 +56,8 @@ var goldenOpts = struct { // This will skip any assertions. Useful when adding new golden variants to a test. devMode bool }{ - writeGoldenFiles: false, - devMode: false, + writeGoldenFiles: true, + devMode: true, } // Note, if you're enabling writeGoldenFiles on a MacOS ARM 64 you need to run the test with GOARCH=amd64, e.g. @@ -133,6 +133,55 @@ 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) }} + +{{ 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 := 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() diff --git a/resources/images/testdata/images_golden/filters_mask/transparant.png b/resources/images/testdata/images_golden/filters_mask/transparant.png new file mode 100644 index 00000000000..73e9c40dd06 Binary files /dev/null and b/resources/images/testdata/images_golden/filters_mask/transparant.png differ diff --git a/resources/images/testdata/images_golden/filters_mask/yellow.jpg b/resources/images/testdata/images_golden/filters_mask/yellow.jpg new file mode 100644 index 00000000000..a87123536ea Binary files /dev/null and b/resources/images/testdata/images_golden/filters_mask/yellow.jpg differ diff --git a/resources/testdata/mask.png b/resources/testdata/mask.png new file mode 100644 index 00000000000..26ac8579194 Binary files /dev/null and b/resources/testdata/mask.png differ