memos/internal/testutil/image.go

24 lines
580 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package testutil
import (
"bytes"
"image"
"image/color"
"image/jpeg"
)
// BuildJPEG returns a solid-color width×height JPEG blob for tests.
func BuildJPEG(width, height int) []byte {
img := image.NewRGBA(image.Rect(0, 0, width, height))
for y := range height {
for x := range width {
img.Set(x, y, color.RGBA{R: 80, G: 120, B: 160, A: 255})
}
}
var buffer bytes.Buffer
if err := jpeg.Encode(&buffer, img, &jpeg.Options{Quality: 90}); err != nil {
// Encoding an in-memory RGBA image cannot fail with valid dimensions.
panic(err)
}
return buffer.Bytes()
}