-
Notifications
You must be signed in to change notification settings - Fork 0
/
croptop_test.go
45 lines (35 loc) · 883 Bytes
/
croptop_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package croptop_test
import (
"bytes"
"os"
"testing"
"github.com/disintegration/imaging"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stevenferrer/croptop"
)
func TestCrop(t *testing.T) {
_, err := croptop.Decode(new(bytes.Buffer))
assert.Error(t, err)
r, err := os.Open("./fixtures/alicia-vikander.jpg")
require.NoError(t, err)
img, err := croptop.Decode(r)
require.NoError(t, err)
height := 296.0
width := 197.0
offsetX := 666.0
offsetY := 66.0
buf := &bytes.Buffer{}
err = img.Height(height).Width(width).
OffsetX(offsetX).OffsetY(offsetY).
Crop().Encode(buf)
require.NoError(t, err)
// verify the dimensions of the resulting image
out, err := imaging.Decode(buf)
require.NoError(t, err)
rect := out.Bounds()
// height
assert.Equal(t, 296, rect.Max.Y)
// width
assert.Equal(t, 197, rect.Max.X)
}