diff --git a/resources/images/images_golden_integration_test.go b/resources/images/images_golden_integration_test.go index 20f3d23f99e..49d90a79394 100644 --- a/resources/images/images_golden_integration_test.go +++ b/resources/images/images_golden_integration_test.go @@ -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() 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..ffbd84c9636 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/wide.jpg b/resources/images/testdata/images_golden/filters_mask/wide.jpg new file mode 100644 index 00000000000..38ef715ba8c Binary files /dev/null and b/resources/images/testdata/images_golden/filters_mask/wide.jpg 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