[MM-62191] Remove disintegration/imaging dependency (#29657)
* Remove disintegration/imaging dependency * Simplify FillCenter logic --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
28dbc3cabb
Коммит
316cde2569
@@ -5,8 +5,10 @@ package imaging
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"testing"
|
||||
|
||||
"github.com/anthonynsimon/bild/transform"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -75,3 +77,96 @@ func TestGenerateThumbnail(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func createTestImage(t *testing.T, width, height int) image.Image {
|
||||
t.Helper()
|
||||
img := image.NewNRGBA(image.Rect(0, 0, width, height))
|
||||
for y := 0; y < height; y++ {
|
||||
for x := 0; x < width; x++ {
|
||||
img.Set(x, y, color.NRGBA{uint8(x % 256), uint8(y % 256), 0, 255})
|
||||
}
|
||||
}
|
||||
return img
|
||||
}
|
||||
|
||||
func TestResize(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
img image.Image
|
||||
targetW int
|
||||
targetH int
|
||||
expectedW int
|
||||
expectedH int
|
||||
}{
|
||||
{
|
||||
name: "zero target dimensions",
|
||||
img: createTestImage(t, 100, 50),
|
||||
targetW: 0,
|
||||
targetH: 0,
|
||||
expectedW: 0,
|
||||
expectedH: 0,
|
||||
},
|
||||
{
|
||||
name: "negative target dimensions",
|
||||
img: createTestImage(t, 100, 50),
|
||||
targetW: -1,
|
||||
targetH: 25,
|
||||
expectedW: 0,
|
||||
expectedH: 0,
|
||||
},
|
||||
{
|
||||
name: "zero source dimensions",
|
||||
img: createTestImage(t, 0, 0),
|
||||
targetW: 50,
|
||||
targetH: 25,
|
||||
expectedW: 0,
|
||||
expectedH: 0,
|
||||
},
|
||||
{
|
||||
name: "preserve aspect ratio with width",
|
||||
img: createTestImage(t, 100, 50),
|
||||
targetW: 50,
|
||||
targetH: 0,
|
||||
expectedW: 50,
|
||||
expectedH: 25,
|
||||
},
|
||||
{
|
||||
name: "preserve aspect ratio with width, height > width",
|
||||
img: createTestImage(t, 50, 100),
|
||||
targetW: 50,
|
||||
targetH: 0,
|
||||
expectedW: 50,
|
||||
expectedH: 100,
|
||||
},
|
||||
{
|
||||
name: "preserve aspect ratio with height",
|
||||
img: createTestImage(t, 100, 50),
|
||||
targetW: 0,
|
||||
targetH: 25,
|
||||
expectedW: 50,
|
||||
expectedH: 25,
|
||||
},
|
||||
{
|
||||
name: "preserve aspect ratio with height, height > width",
|
||||
img: createTestImage(t, 50, 100),
|
||||
targetW: 0,
|
||||
targetH: 25,
|
||||
expectedW: 13,
|
||||
expectedH: 25,
|
||||
},
|
||||
{
|
||||
name: "valid target dimensions",
|
||||
img: createTestImage(t, 100, 50),
|
||||
targetW: 50,
|
||||
targetH: 25,
|
||||
expectedW: 50,
|
||||
expectedH: 25,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
resizedImg := Resize(tc.img, tc.targetW, tc.targetH, transform.Lanczos)
|
||||
require.Equal(t, tc.expectedW, resizedImg.Bounds().Dx())
|
||||
require.Equal(t, tc.expectedH, resizedImg.Bounds().Dy())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user