MCPcopy
hub / github.com/docker/docker-agent / encodePNGBytes

Function encodePNGBytes

pkg/chat/attach_test.go:39–64  ·  view source on GitHub ↗
(w, h int, alpha bool)

Source from the content-addressed store, hash-verified

37}
38
39func encodePNGBytes(w, h int, alpha bool) []byte {
40 if alpha {
41 img := image.NewNRGBA(image.Rect(0, 0, w, h))
42 for y := range h {
43 for x := range w {
44 img.Set(x, y, color.NRGBA{R: 0, G: 128, B: 255, A: 128})
45 }
46 }
47 var buf bytes.Buffer
48 if err := png.Encode(&buf, img); err != nil {
49 panic(err)
50 }
51 return buf.Bytes()
52 }
53 img := image.NewRGBA(image.Rect(0, 0, w, h))
54 for y := range h {
55 for x := range w {
56 img.Set(x, y, color.RGBA{R: 0, G: 128, B: 255, A: 255})
57 }
58 }
59 var buf bytes.Buffer
60 if err := png.Encode(&buf, img); err != nil {
61 panic(err)
62 }
63 return buf.Bytes()
64}
65
66func writeTempFile(t *testing.T, ext string, data []byte) string {
67 t.Helper()

Calls 2

BytesMethod · 0.95
SetMethod · 0.45

Tested by

no test coverage detected