mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-08 23:18:19 -07:00
Merge pull request #271 from Dynom/ImprovingAreaWidthTestCoverage
Adding a test case that verifies #250
This commit is contained in:
commit
15cd115607
2 changed files with 52 additions and 0 deletions
|
|
@ -12,6 +12,10 @@ import (
|
|||
"math"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrExtractAreaParamsRequired = errors.New("extract area width/height params are required")
|
||||
)
|
||||
|
||||
// resizer is used to transform a given image as byte buffer
|
||||
// with the passed options.
|
||||
func resizer(buf []byte, o Options) ([]byte, error) {
|
||||
|
|
|
|||
|
|
@ -364,6 +364,54 @@ func TestExtractCustomAxis(t *testing.T) {
|
|||
Write("testdata/test_extract_custom_axis_out.jpg", newImg)
|
||||
}
|
||||
|
||||
func TestExtractOrEmbedImage(t *testing.T) {
|
||||
buf, _ := Read("testdata/test.jpg")
|
||||
input, _, err := loadImage(buf)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to load image %s", err)
|
||||
}
|
||||
|
||||
o := Options{
|
||||
Top: 10,
|
||||
Left: 10,
|
||||
Width: 100,
|
||||
Height: 200,
|
||||
|
||||
// Fields to test
|
||||
AreaHeight: 0,
|
||||
AreaWidth: 0,
|
||||
|
||||
Quality: 100, /* Needs a value to satisfy libvips */
|
||||
}
|
||||
|
||||
result, err := extractOrEmbedImage(input, o)
|
||||
if err != nil {
|
||||
if err == ErrExtractAreaParamsRequired {
|
||||
t.Fatalf("Expecting AreaWidth and AreaHeight to have been defined")
|
||||
}
|
||||
|
||||
t.Fatalf("Unknown error occurred %s", err)
|
||||
}
|
||||
|
||||
image, err := saveImage(result, o)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed saving image %s", err)
|
||||
}
|
||||
|
||||
test, err := Size(image)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed fetching the size %s", err)
|
||||
}
|
||||
|
||||
if test.Height != o.Height {
|
||||
t.Errorf("Extract failed, resulting Height %d doesn't match %d", test.Height, o.Height)
|
||||
}
|
||||
|
||||
if test.Width != o.Width {
|
||||
t.Errorf("Extract failed, resulting Width %d doesn't match %d", test.Width, o.Width)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvert(t *testing.T) {
|
||||
width, height := 300, 240
|
||||
formats := [3]ImageType{PNG, WEBP, JPEG}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue