2025-06-05 20:19:20 +03:00
|
|
|
package processing
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
|
2025-11-20 01:26:21 +06:00
|
|
|
"github.com/imgproxy/imgproxy/v3/errctx"
|
2025-09-05 16:22:57 +02:00
|
|
|
"github.com/imgproxy/imgproxy/v3/fetcher"
|
2025-06-05 20:19:20 +03:00
|
|
|
"github.com/imgproxy/imgproxy/v3/imagedata"
|
2025-09-15 02:15:44 +03:00
|
|
|
"github.com/imgproxy/imgproxy/v3/logger"
|
2025-06-05 20:19:20 +03:00
|
|
|
"github.com/imgproxy/imgproxy/v3/options"
|
2025-09-23 20:16:36 +03:00
|
|
|
"github.com/imgproxy/imgproxy/v3/options/keys"
|
2025-09-16 17:04:21 +02:00
|
|
|
"github.com/imgproxy/imgproxy/v3/security"
|
2025-09-22 19:32:34 +02:00
|
|
|
"github.com/imgproxy/imgproxy/v3/testutil"
|
2025-06-05 20:19:20 +03:00
|
|
|
"github.com/imgproxy/imgproxy/v3/vips"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ProcessingTestSuite struct {
|
2025-09-22 19:32:34 +02:00
|
|
|
testutil.LazySuite
|
|
|
|
|
|
|
|
|
|
imageDataFactory testutil.LazyObj[*imagedata.Factory]
|
|
|
|
|
securityConfig testutil.LazyObj[*security.Config]
|
|
|
|
|
security testutil.LazyObj[*security.Checker]
|
2025-09-23 15:55:04 +02:00
|
|
|
config testutil.LazyObj[*Config]
|
|
|
|
|
processor testutil.LazyObj[*Processor]
|
2025-06-05 20:19:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ProcessingTestSuite) SetupSuite() {
|
2025-09-25 22:34:02 +03:00
|
|
|
vipsCfg := vips.NewDefaultConfig()
|
|
|
|
|
s.Require().NoError(vips.Init(&vipsCfg))
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-15 02:15:44 +03:00
|
|
|
logger.Mute()
|
2025-09-05 16:22:57 +02:00
|
|
|
|
2025-09-22 19:32:34 +02:00
|
|
|
s.imageDataFactory, _ = testutil.NewLazySuiteObj(s, func() (*imagedata.Factory, error) {
|
|
|
|
|
c := fetcher.NewDefaultConfig()
|
|
|
|
|
f, err := fetcher.New(&c)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2025-09-05 16:22:57 +02:00
|
|
|
|
2025-11-01 00:04:27 +03:00
|
|
|
return imagedata.NewFactory(f, nil), nil
|
2025-09-22 19:32:34 +02:00
|
|
|
})
|
2025-09-16 17:04:21 +02:00
|
|
|
|
2025-09-22 19:32:34 +02:00
|
|
|
s.securityConfig, _ = testutil.NewLazySuiteObj(s, func() (*security.Config, error) {
|
|
|
|
|
c := security.NewDefaultConfig()
|
2025-09-16 17:04:21 +02:00
|
|
|
|
2025-10-31 21:28:33 +03:00
|
|
|
c.MaxSrcResolution = 10 * 1024 * 1024
|
|
|
|
|
c.MaxSrcFileSize = 10 * 1024 * 1024
|
|
|
|
|
c.MaxAnimationFrames = 100
|
|
|
|
|
c.MaxAnimationFrameResolution = 10 * 1024 * 1024
|
2025-09-16 17:04:21 +02:00
|
|
|
|
2025-09-22 19:32:34 +02:00
|
|
|
return &c, nil
|
|
|
|
|
})
|
2025-09-16 17:04:21 +02:00
|
|
|
|
2025-09-22 19:32:34 +02:00
|
|
|
s.security, _ = testutil.NewLazySuiteObj(s, func() (*security.Checker, error) {
|
|
|
|
|
return security.New(s.securityConfig())
|
|
|
|
|
})
|
|
|
|
|
|
2025-09-23 15:55:04 +02:00
|
|
|
s.config, _ = testutil.NewLazySuiteObj(s, func() (*Config, error) {
|
|
|
|
|
c := NewDefaultConfig()
|
|
|
|
|
return &c, nil
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
s.processor, _ = testutil.NewLazySuiteObj(s, func() (*Processor, error) {
|
2025-10-31 21:28:33 +03:00
|
|
|
return New(s.config(), s.security(), nil)
|
2025-09-23 15:55:04 +02:00
|
|
|
})
|
2025-06-05 20:19:20 +03:00
|
|
|
}
|
|
|
|
|
|
2025-09-15 02:15:44 +03:00
|
|
|
func (s *ProcessingTestSuite) TearDownSuite() {
|
|
|
|
|
logger.Unmute()
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-01 15:44:21 +02:00
|
|
|
func (s *ProcessingTestSuite) openFile(name string) imagedata.ImageData {
|
2025-06-05 20:19:20 +03:00
|
|
|
wd, err := os.Getwd()
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
path := filepath.Join(wd, "..", "testdata", name)
|
|
|
|
|
|
2025-09-22 19:32:34 +02:00
|
|
|
imagedata, err := s.imageDataFactory().NewFromPath(path)
|
2025-06-05 20:19:20 +03:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
|
|
return imagedata
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-06 16:46:35 +02:00
|
|
|
func (s *ProcessingTestSuite) checkSize(r *Result, width, height int) {
|
|
|
|
|
s.Require().NotNil(r)
|
|
|
|
|
s.Require().Equal(width, r.ResultWidth, "Width mismatch")
|
|
|
|
|
s.Require().Equal(height, r.ResultHeight, "Height mismatch")
|
2025-06-05 20:19:20 +03:00
|
|
|
}
|
|
|
|
|
|
2025-09-23 20:16:36 +03:00
|
|
|
func (s *ProcessingTestSuite) processImageAndCheck(
|
|
|
|
|
imgdata imagedata.ImageData,
|
2025-09-25 19:48:53 +03:00
|
|
|
o *options.Options,
|
2025-09-23 20:16:36 +03:00
|
|
|
expectedWidth, expectedHeight int,
|
|
|
|
|
) {
|
2025-10-31 21:28:33 +03:00
|
|
|
result, err := s.processor().ProcessImage(s.T().Context(), imgdata, o)
|
2025-09-23 15:55:04 +02:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
s.Require().NotNil(result)
|
|
|
|
|
|
|
|
|
|
s.checkSize(result, expectedWidth, expectedHeight)
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-05 20:19:20 +03:00
|
|
|
func (s *ProcessingTestSuite) TestResizeToFit() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.ResizingType, ResizeFit)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
width int
|
|
|
|
|
height int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
|
|
|
|
}{
|
|
|
|
|
{width: 50, height: 50, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 50, height: 20, outWidth: 40, outHeight: 20},
|
|
|
|
|
{width: 20, height: 50, outWidth: 20, outHeight: 10},
|
|
|
|
|
{width: 300, height: 300, outWidth: 200, outHeight: 100},
|
|
|
|
|
{width: 300, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 100, height: 300, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 0, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 50, height: 0, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 0, height: 200, outWidth: 200, outHeight: 100},
|
|
|
|
|
{width: 300, height: 0, outWidth: 200, outHeight: 100},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
s.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-05 20:19:20 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ProcessingTestSuite) TestResizeToFitEnlarge() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.ResizingType, ResizeFit)
|
|
|
|
|
o.Set(keys.Enlarge, true)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
width int
|
|
|
|
|
height int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
|
|
|
|
}{
|
|
|
|
|
{width: 50, height: 50, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 50, height: 20, outWidth: 40, outHeight: 20},
|
|
|
|
|
{width: 20, height: 50, outWidth: 20, outHeight: 10},
|
|
|
|
|
{width: 300, height: 300, outWidth: 300, outHeight: 150},
|
|
|
|
|
{width: 300, height: 125, outWidth: 250, outHeight: 125},
|
|
|
|
|
{width: 250, height: 300, outWidth: 250, outHeight: 125},
|
|
|
|
|
{width: 0, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 50, height: 0, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 0, height: 200, outWidth: 400, outHeight: 200},
|
|
|
|
|
{width: 300, height: 0, outWidth: 300, outHeight: 150},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
s.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-05 20:19:20 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ProcessingTestSuite) TestResizeToFitExtend() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.ResizingType, ResizeFit)
|
|
|
|
|
o.Set(keys.ExtendEnabled, true)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
width int
|
|
|
|
|
height int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
|
|
|
|
}{
|
|
|
|
|
{width: 50, height: 50, outWidth: 50, outHeight: 50},
|
|
|
|
|
{width: 50, height: 20, outWidth: 50, outHeight: 20},
|
|
|
|
|
{width: 20, height: 50, outWidth: 20, outHeight: 50},
|
|
|
|
|
{width: 300, height: 300, outWidth: 300, outHeight: 300},
|
|
|
|
|
{width: 300, height: 125, outWidth: 300, outHeight: 125},
|
|
|
|
|
{width: 250, height: 300, outWidth: 250, outHeight: 300},
|
|
|
|
|
{width: 0, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 50, height: 0, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 0, height: 200, outWidth: 200, outHeight: 200},
|
|
|
|
|
{width: 300, height: 0, outWidth: 300, outHeight: 100},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
s.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-05 20:19:20 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ProcessingTestSuite) TestResizeToFitExtendAR() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.ResizingType, ResizeFit)
|
|
|
|
|
o.Set(keys.ExtendAspectRatioEnabled, true)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
width int
|
|
|
|
|
height int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
|
|
|
|
}{
|
|
|
|
|
{width: 50, height: 50, outWidth: 50, outHeight: 50},
|
|
|
|
|
{width: 50, height: 20, outWidth: 50, outHeight: 20},
|
|
|
|
|
{width: 20, height: 50, outWidth: 20, outHeight: 50},
|
|
|
|
|
{width: 300, height: 300, outWidth: 200, outHeight: 200},
|
|
|
|
|
{width: 300, height: 125, outWidth: 240, outHeight: 100},
|
|
|
|
|
{width: 250, height: 500, outWidth: 200, outHeight: 400},
|
|
|
|
|
{width: 0, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 50, height: 0, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 0, height: 200, outWidth: 200, outHeight: 100},
|
|
|
|
|
{width: 300, height: 0, outWidth: 200, outHeight: 100},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
s.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-05 20:19:20 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ProcessingTestSuite) TestResizeToFill() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.ResizingType, ResizeFill)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
width int
|
|
|
|
|
height int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
|
|
|
|
}{
|
|
|
|
|
{width: 50, height: 50, outWidth: 50, outHeight: 50},
|
|
|
|
|
{width: 50, height: 20, outWidth: 50, outHeight: 20},
|
|
|
|
|
{width: 20, height: 50, outWidth: 20, outHeight: 50},
|
|
|
|
|
{width: 300, height: 300, outWidth: 200, outHeight: 100},
|
|
|
|
|
{width: 300, height: 50, outWidth: 200, outHeight: 50},
|
|
|
|
|
{width: 100, height: 300, outWidth: 100, outHeight: 100},
|
|
|
|
|
{width: 0, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 50, height: 0, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 0, height: 200, outWidth: 200, outHeight: 100},
|
|
|
|
|
{width: 300, height: 0, outWidth: 200, outHeight: 100},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
s.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-05 20:19:20 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ProcessingTestSuite) TestResizeToFillEnlarge() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.ResizingType, ResizeFill)
|
|
|
|
|
o.Set(keys.Enlarge, true)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
width int
|
|
|
|
|
height int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
|
|
|
|
}{
|
|
|
|
|
{width: 50, height: 50, outWidth: 50, outHeight: 50},
|
|
|
|
|
{width: 50, height: 20, outWidth: 50, outHeight: 20},
|
|
|
|
|
{width: 20, height: 50, outWidth: 20, outHeight: 50},
|
|
|
|
|
{width: 300, height: 300, outWidth: 300, outHeight: 300},
|
|
|
|
|
{width: 300, height: 125, outWidth: 300, outHeight: 125},
|
|
|
|
|
{width: 250, height: 300, outWidth: 250, outHeight: 300},
|
|
|
|
|
{width: 0, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 50, height: 0, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 0, height: 200, outWidth: 400, outHeight: 200},
|
|
|
|
|
{width: 300, height: 0, outWidth: 300, outHeight: 150},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
s.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-05 20:19:20 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ProcessingTestSuite) TestResizeToFillExtend() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.ResizingType, ResizeFill)
|
|
|
|
|
o.Set(keys.ExtendEnabled, true)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
width int
|
|
|
|
|
height int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
|
|
|
|
}{
|
|
|
|
|
{width: 50, height: 50, outWidth: 50, outHeight: 50},
|
|
|
|
|
{width: 50, height: 20, outWidth: 50, outHeight: 20},
|
|
|
|
|
{width: 20, height: 50, outWidth: 20, outHeight: 50},
|
|
|
|
|
{width: 300, height: 300, outWidth: 300, outHeight: 300},
|
|
|
|
|
{width: 300, height: 125, outWidth: 300, outHeight: 125},
|
|
|
|
|
{width: 250, height: 300, outWidth: 250, outHeight: 300},
|
|
|
|
|
{width: 300, height: 50, outWidth: 300, outHeight: 50},
|
|
|
|
|
{width: 100, height: 300, outWidth: 100, outHeight: 300},
|
|
|
|
|
{width: 0, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 50, height: 0, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 0, height: 200, outWidth: 200, outHeight: 200},
|
|
|
|
|
{width: 300, height: 0, outWidth: 300, outHeight: 100},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
s.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-05 20:19:20 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ProcessingTestSuite) TestResizeToFillExtendAR() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.ResizingType, ResizeFill)
|
|
|
|
|
o.Set(keys.ExtendAspectRatioEnabled, true)
|
|
|
|
|
o.Set(keys.ExtendAspectRatioGravityType, GravityCenter)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
width int
|
|
|
|
|
height int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
|
|
|
|
}{
|
|
|
|
|
{width: 50, height: 50, outWidth: 50, outHeight: 50},
|
|
|
|
|
{width: 50, height: 20, outWidth: 50, outHeight: 20},
|
|
|
|
|
{width: 20, height: 50, outWidth: 20, outHeight: 50},
|
|
|
|
|
{width: 300, height: 300, outWidth: 200, outHeight: 200},
|
|
|
|
|
{width: 300, height: 125, outWidth: 240, outHeight: 100},
|
|
|
|
|
{width: 250, height: 500, outWidth: 200, outHeight: 400},
|
|
|
|
|
{width: 300, height: 50, outWidth: 300, outHeight: 50},
|
|
|
|
|
{width: 100, height: 300, outWidth: 100, outHeight: 300},
|
|
|
|
|
{width: 0, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 50, height: 0, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 0, height: 200, outWidth: 200, outHeight: 100},
|
|
|
|
|
{width: 300, height: 0, outWidth: 200, outHeight: 100},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
s.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-05 20:19:20 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ProcessingTestSuite) TestResizeToFillDown() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.ResizingType, ResizeFillDown)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
width int
|
|
|
|
|
height int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
|
|
|
|
}{
|
|
|
|
|
{width: 50, height: 50, outWidth: 50, outHeight: 50},
|
|
|
|
|
{width: 50, height: 20, outWidth: 50, outHeight: 20},
|
|
|
|
|
{width: 20, height: 50, outWidth: 20, outHeight: 50},
|
|
|
|
|
{width: 300, height: 300, outWidth: 100, outHeight: 100},
|
|
|
|
|
{width: 300, height: 125, outWidth: 200, outHeight: 83},
|
|
|
|
|
{width: 250, height: 300, outWidth: 83, outHeight: 100},
|
|
|
|
|
{width: 0, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 50, height: 0, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 0, height: 200, outWidth: 200, outHeight: 100},
|
|
|
|
|
{width: 300, height: 0, outWidth: 200, outHeight: 100},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
s.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-05 20:19:20 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ProcessingTestSuite) TestResizeToFillDownEnlarge() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.ResizingType, ResizeFillDown)
|
|
|
|
|
o.Set(keys.Enlarge, true)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
width int
|
|
|
|
|
height int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
|
|
|
|
}{
|
|
|
|
|
{width: 50, height: 50, outWidth: 50, outHeight: 50},
|
|
|
|
|
{width: 50, height: 20, outWidth: 50, outHeight: 20},
|
|
|
|
|
{width: 20, height: 50, outWidth: 20, outHeight: 50},
|
|
|
|
|
{width: 300, height: 300, outWidth: 300, outHeight: 300},
|
|
|
|
|
{width: 300, height: 125, outWidth: 300, outHeight: 125},
|
|
|
|
|
{width: 250, height: 300, outWidth: 250, outHeight: 300},
|
|
|
|
|
{width: 0, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 50, height: 0, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 0, height: 200, outWidth: 400, outHeight: 200},
|
|
|
|
|
{width: 300, height: 0, outWidth: 300, outHeight: 150},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
s.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-05 20:19:20 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ProcessingTestSuite) TestResizeToFillDownExtend() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.ResizingType, ResizeFillDown)
|
|
|
|
|
o.Set(keys.ExtendEnabled, true)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
width int
|
|
|
|
|
height int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
|
|
|
|
}{
|
|
|
|
|
{width: 50, height: 50, outWidth: 50, outHeight: 50},
|
|
|
|
|
{width: 50, height: 20, outWidth: 50, outHeight: 20},
|
|
|
|
|
{width: 20, height: 50, outWidth: 20, outHeight: 50},
|
|
|
|
|
{width: 300, height: 300, outWidth: 300, outHeight: 300},
|
|
|
|
|
{width: 300, height: 125, outWidth: 300, outHeight: 125},
|
|
|
|
|
{width: 250, height: 300, outWidth: 250, outHeight: 300},
|
|
|
|
|
{width: 300, height: 50, outWidth: 300, outHeight: 50},
|
|
|
|
|
{width: 100, height: 300, outWidth: 100, outHeight: 300},
|
|
|
|
|
{width: 0, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 50, height: 0, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 0, height: 200, outWidth: 200, outHeight: 200},
|
|
|
|
|
{width: 300, height: 0, outWidth: 300, outHeight: 100},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
s.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-05 20:19:20 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ProcessingTestSuite) TestResizeToFillDownExtendAR() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.ResizingType, ResizeFillDown)
|
|
|
|
|
o.Set(keys.ExtendAspectRatioEnabled, true)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
width int
|
|
|
|
|
height int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
|
|
|
|
}{
|
|
|
|
|
{width: 50, height: 50, outWidth: 50, outHeight: 50},
|
|
|
|
|
{width: 50, height: 20, outWidth: 50, outHeight: 20},
|
|
|
|
|
{width: 20, height: 50, outWidth: 20, outHeight: 50},
|
|
|
|
|
{width: 300, height: 300, outWidth: 100, outHeight: 100},
|
|
|
|
|
{width: 300, height: 125, outWidth: 200, outHeight: 83},
|
|
|
|
|
{width: 250, height: 300, outWidth: 83, outHeight: 100},
|
|
|
|
|
{width: 0, height: 50, outWidth: 100, outHeight: 50},
|
|
|
|
|
{width: 50, height: 0, outWidth: 50, outHeight: 25},
|
|
|
|
|
{width: 0, height: 200, outWidth: 200, outHeight: 100},
|
|
|
|
|
{width: 300, height: 0, outWidth: 200, outHeight: 100},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
s.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
2025-06-05 20:19:20 +03:00
|
|
|
|
2025-09-25 19:48:53 +03:00
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-05 20:19:20 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-06 19:28:41 +03:00
|
|
|
func (s *ProcessingTestSuite) TestResultSizeLimit() {
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
|
|
|
|
|
|
|
|
|
testCases := []struct {
|
2025-09-23 20:16:36 +03:00
|
|
|
limit int
|
|
|
|
|
width int
|
|
|
|
|
height int
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType ResizeType
|
2025-09-23 20:16:36 +03:00
|
|
|
enlarge bool
|
|
|
|
|
extend bool
|
|
|
|
|
extendAR bool
|
|
|
|
|
paddingTop int
|
|
|
|
|
paddingRight int
|
|
|
|
|
paddingBottom int
|
|
|
|
|
paddingLeft int
|
|
|
|
|
rotate int
|
|
|
|
|
outWidth int
|
|
|
|
|
outHeight int
|
2025-06-06 19:28:41 +03:00
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
limit: 1000,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFit,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 100,
|
|
|
|
|
outHeight: 50,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFit,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 25,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 0,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFit,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 25,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 100,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFit,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 100,
|
|
|
|
|
outHeight: 50,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 150,
|
|
|
|
|
height: 0,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFit,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 25,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 1000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFit,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 100,
|
|
|
|
|
outHeight: 50,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 1000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFit,
|
2025-06-06 19:28:41 +03:00
|
|
|
enlarge: true,
|
|
|
|
|
outWidth: 100,
|
|
|
|
|
outHeight: 50,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 2000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFit,
|
2025-06-06 19:28:41 +03:00
|
|
|
extend: true,
|
|
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 2000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFit,
|
2025-06-06 19:28:41 +03:00
|
|
|
extendAR: true,
|
|
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 150,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFit,
|
2025-06-06 19:28:41 +03:00
|
|
|
rotate: 90,
|
|
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 0,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFit,
|
2025-06-06 19:28:41 +03:00
|
|
|
rotate: 90,
|
|
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
2025-09-23 20:16:36 +03:00
|
|
|
limit: 200,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFit,
|
2025-09-23 20:16:36 +03:00
|
|
|
paddingTop: 100,
|
|
|
|
|
paddingRight: 200,
|
|
|
|
|
paddingBottom: 300,
|
|
|
|
|
paddingLeft: 400,
|
|
|
|
|
outWidth: 200,
|
|
|
|
|
outHeight: 129,
|
2025-06-06 19:28:41 +03:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 1000,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 100,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 50,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 50,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 13,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 1000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 50,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 0,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 25,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 100,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 100,
|
|
|
|
|
outHeight: 50,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 150,
|
|
|
|
|
height: 0,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 25,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 1000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 100,
|
|
|
|
|
outHeight: 50,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 1000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
enlarge: true,
|
|
|
|
|
outWidth: 100,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 2000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
extend: true,
|
|
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 2000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
extendAR: true,
|
|
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 150,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
rotate: 90,
|
|
|
|
|
outWidth: 67,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 0,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-06-06 19:28:41 +03:00
|
|
|
rotate: 90,
|
|
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
2025-09-23 20:16:36 +03:00
|
|
|
limit: 200,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFill,
|
2025-09-23 20:16:36 +03:00
|
|
|
paddingTop: 100,
|
|
|
|
|
paddingRight: 200,
|
|
|
|
|
paddingBottom: 300,
|
|
|
|
|
paddingLeft: 400,
|
|
|
|
|
outWidth: 200,
|
|
|
|
|
outHeight: 144,
|
2025-06-06 19:28:41 +03:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 1000,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 100,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 50,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 50,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 3,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 1000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 5,
|
|
|
|
|
outHeight: 50,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 0,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 25,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 100,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 100,
|
|
|
|
|
outHeight: 50,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 50,
|
|
|
|
|
width: 150,
|
|
|
|
|
height: 0,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 25,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 1000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
outWidth: 100,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 1000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
enlarge: true,
|
|
|
|
|
outWidth: 100,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 2000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
extend: true,
|
|
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 2000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
extendAR: true,
|
|
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 1500,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
rotate: 90,
|
|
|
|
|
outWidth: 67,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 100,
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 0,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-06-06 19:28:41 +03:00
|
|
|
rotate: 90,
|
|
|
|
|
outWidth: 50,
|
|
|
|
|
outHeight: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
2025-09-23 20:16:36 +03:00
|
|
|
limit: 200,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-09-23 20:16:36 +03:00
|
|
|
paddingTop: 100,
|
|
|
|
|
paddingRight: 200,
|
|
|
|
|
paddingBottom: 300,
|
|
|
|
|
paddingLeft: 400,
|
|
|
|
|
outWidth: 200,
|
|
|
|
|
outHeight: 144,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
limit: 200,
|
|
|
|
|
width: 1000,
|
|
|
|
|
height: 1000,
|
2025-09-25 19:48:53 +03:00
|
|
|
resizingType: ResizeFillDown,
|
2025-09-23 20:16:36 +03:00
|
|
|
paddingTop: 100,
|
|
|
|
|
paddingRight: 200,
|
|
|
|
|
paddingBottom: 300,
|
|
|
|
|
paddingLeft: 400,
|
|
|
|
|
outWidth: 200,
|
|
|
|
|
outHeight: 144,
|
2025-06-06 19:28:41 +03:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
name := fmt.Sprintf("%s_%dx%d_limit_%d", tc.resizingType, tc.width, tc.height, tc.limit)
|
|
|
|
|
if tc.enlarge {
|
|
|
|
|
name += "_enlarge"
|
|
|
|
|
}
|
|
|
|
|
if tc.extend {
|
|
|
|
|
name += "_extend"
|
|
|
|
|
}
|
|
|
|
|
if tc.extendAR {
|
|
|
|
|
name += "_extendAR"
|
|
|
|
|
}
|
|
|
|
|
if tc.rotate != 0 {
|
|
|
|
|
name += fmt.Sprintf("_rot_%d", tc.rotate)
|
|
|
|
|
}
|
2025-09-23 20:16:36 +03:00
|
|
|
if tc.paddingTop > 0 || tc.paddingRight > 0 || tc.paddingBottom > 0 || tc.paddingLeft > 0 {
|
|
|
|
|
name += fmt.Sprintf(
|
|
|
|
|
"_padding_%dx%dx%dx%d",
|
|
|
|
|
tc.paddingTop, tc.paddingRight, tc.paddingBottom, tc.paddingLeft,
|
|
|
|
|
)
|
2025-06-06 19:28:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.Run(name, func() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.MaxResultDimension, tc.limit)
|
|
|
|
|
o.Set(keys.Width, tc.width)
|
|
|
|
|
o.Set(keys.Height, tc.height)
|
|
|
|
|
o.Set(keys.ResizingType, tc.resizingType)
|
|
|
|
|
o.Set(keys.Enlarge, tc.enlarge)
|
|
|
|
|
o.Set(keys.ExtendEnabled, tc.extend)
|
|
|
|
|
o.Set(keys.ExtendAspectRatioEnabled, tc.extendAR)
|
|
|
|
|
o.Set(keys.Rotate, tc.rotate)
|
|
|
|
|
o.Set(keys.PaddingTop, tc.paddingTop)
|
|
|
|
|
o.Set(keys.PaddingRight, tc.paddingRight)
|
|
|
|
|
o.Set(keys.PaddingBottom, tc.paddingBottom)
|
|
|
|
|
o.Set(keys.PaddingLeft, tc.paddingLeft)
|
|
|
|
|
|
|
|
|
|
s.processImageAndCheck(imgdata, o, tc.outWidth, tc.outHeight)
|
2025-06-06 19:28:41 +03:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-13 11:49:48 +02:00
|
|
|
func (s *ProcessingTestSuite) TestImageResolutionTooLarge() {
|
2025-09-25 19:48:53 +03:00
|
|
|
o := options.New()
|
|
|
|
|
o.Set(keys.MaxSrcResolution, 1)
|
2025-08-13 11:49:48 +02:00
|
|
|
|
|
|
|
|
imgdata := s.openFile("test2.jpg")
|
2025-10-31 21:28:33 +03:00
|
|
|
_, err := s.processor().ProcessImage(s.T().Context(), imgdata, o)
|
2025-08-13 11:49:48 +02:00
|
|
|
|
|
|
|
|
s.Require().Error(err)
|
2025-11-20 01:26:21 +06:00
|
|
|
s.Require().Equal(422, errctx.Wrap(err).StatusCode())
|
2025-08-13 11:49:48 +02:00
|
|
|
}
|
|
|
|
|
|
2025-06-05 20:19:20 +03:00
|
|
|
func TestProcessing(t *testing.T) {
|
|
|
|
|
suite.Run(t, new(ProcessingTestSuite))
|
|
|
|
|
}
|