-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_test.go
55 lines (39 loc) · 1.3 KB
/
image_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
48
49
50
51
52
53
54
55
package main
import (
"errors"
"fmt"
"image"
"os"
"testing"
)
func TestWritesOntoDrawable(t *testing.T) {
const filePath = "images/PXL_20210705_154615696.jpg"
const fontPath = "fonts/OpenSans-VariableFont_wdth,wght.ttf"
lines := []string{
"my line",
}
font := LoadFontFromPath(fontPath)
if "*truetype.Font" != fmt.Sprintf("%T", font) {
t.Errorf("LoadFontFromPath(%s) returned %T want *truetype.Font", fontPath, font)
}
drawable := GetDrawableFromImagePath(filePath)
if "*image.RGBA" != fmt.Sprintf("%T", drawable) {
t.Errorf("GetDrawableFromImagePath(%s) returned %T want *image.RGBA", filePath, drawable)
}
ftContext := GetFreetypeContext(font, 72.0, 16, drawable)
if "*freetype.Context" != fmt.Sprintf("%T", ftContext) {
t.Errorf("GetFreetypeContext() returned %T want *freetype.Context", ftContext)
}
rectangle := image.Rect(0, 0, 10, 10)
WriteLinesOnRectangle(rectangle, ftContext, lines, 72, 0)
}
func TestWritesToPngFile(t *testing.T) {
const outPath = "/var/tmp/test.png"
const inPath = "images/PXL_20210705_154615696.jpg"
drawable := GetDrawableFromImagePath(inPath)
WriteToPngFile(outPath, drawable)
if _, err := os.Stat(outPath); errors.Is(err, os.ErrNotExist) {
t.Errorf("WriteToPngFile(%s, drawable) did not write to %s", outPath, outPath)
}
os.Remove(outPath)
}