Skip to content

Commit

Permalink
resources/images: Add some mask tests
Browse files Browse the repository at this point in the history
Closes #13244
  • Loading branch information
bep committed Jan 11, 2025
1 parent 71fae99 commit 06cc867
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions resources/images/images_golden_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/testdata/mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 06cc867

Please sign in to comment.