imagetesting.RunGolden(opts)
}
+
+func TestPNGIssue14288(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- assets/qr.png --
+sourcefilename: testdata/images_golden/funcs/qr-level-high_scale-6.png
+-- layouts/home.html --
+{{ $img := resources.Get "qr.png" }}
+images.Config: {{ (images.Config "assets/qr.png").Width }}
+Resize to 100x100: {{ ($img.Resize "100x100" ).Width }}
+Brightnes method: {{ ($img.Filter (images.Brightness 12) ).RelPermalink }}
+Brightnes func: {{ ($img | images.Filter (images.Brightness 12) ).RelPermalink }}
+`
+
+ b := hugolib.Test(t, files)
+ b.AssertFileContent("public/index.html", `
+images.Config: 222
+Resize to 100x100: 100
+Brightnes method: /qr_hu_d5f06fd7594d0594.png
+Brightnes func: /qr_hu_d5f06fd7594d0594.png
+`)
+}
"bytes"
"image"
"image/color"
- "image/png"
"path/filepath"
"testing"
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/config/testconfig"
+ "github.com/gohugoio/hugo/resources/images"
"github.com/spf13/afero"
"github.com/spf13/cast"
)
type tstNoStringer struct{}
+type widthHeight struct {
+ Width int
+ Height int
+}
+
var configTests = []struct {
path any
- input []byte
+ input widthHeight
expect any
}{
{
path: "a.png",
- input: blankImage(10, 10),
+ input: widthHeight{10, 10},
expect: image.Config{
Width: 10,
Height: 10,
},
{
path: "a.png",
- input: blankImage(10, 10),
+ input: widthHeight{10, 10},
expect: image.Config{
Width: 10,
Height: 10,
},
{
path: "b.png",
- input: blankImage(20, 15),
+ input: widthHeight{20, 15},
expect: image.Config{
Width: 20,
Height: 15,
},
{
path: "a.png",
- input: blankImage(20, 15),
+ input: widthHeight{20, 15},
expect: image.Config{
Width: 10,
Height: 10,
// cast path to string for afero.WriteFile
sp, err := cast.ToStringE(test.path)
c.Assert(err, qt.IsNil)
- afero.WriteFile(ns.deps.Fs.Source, filepath.Join(bcfg.WorkingDir(), sp), test.input, 0o755)
+ img := blankImage(d.ResourceSpec.Imaging.Codec, test.input.Width, test.input.Height)
+ afero.WriteFile(ns.deps.Fs.Source, filepath.Join(bcfg.WorkingDir(), sp), img, 0o755)
result, err := ns.Config(test.path)
}
}
-func blankImage(width, height int) []byte {
+func blankImage(codec *images.Codec, width, height int) []byte {
var buf bytes.Buffer
img := image.NewRGBA(image.Rect(0, 0, width, height))
- if err := png.Encode(&buf, img); err != nil {
+ cfg := images.ImageConfig{
+ TargetFormat: images.PNG,
+ }
+ if err := codec.EncodeTo(cfg, &buf, img); err != nil {
panic(err)
}
return buf.Bytes()