forked from rai-project/image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_test.go
47 lines (35 loc) · 893 Bytes
/
write_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
46
47
package image
import (
"image"
"image/png"
"os"
"path/filepath"
"testing"
sourcepath "github.com/GeertJohan/go-sourcepath"
"github.com/c3sr/image/types"
"github.com/stretchr/testify/assert"
)
var (
laneControlImagePath = filepath.Join(sourcepath.MustAbsoluteDir(), "_fixtures", "lane_control.jpg")
)
func TestWrite(t *testing.T) {
reader, err := os.Open(laneControlImagePath)
assert.NoError(t, err)
defer reader.Close()
img0, err := Read(reader)
assert.NoError(t, err)
assert.NotEmpty(t, img0)
img, ok := img0.(*types.RGBImage)
assert.True(t, ok)
toPng("/tmp/image_test.png", img.Pix, img.Bounds())
}
func toPng(filePath string, imgByte []byte, bounds image.Rectangle) {
img := types.NewRGBImage(bounds)
copy(img.Pix, imgByte)
out, _ := os.Create(filePath)
defer out.Close()
err := png.Encode(out, img.ToRGBAImage())
if err != nil {
log.Println(err)
}
}