-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimgbb_test.go
57 lines (46 loc) · 1.17 KB
/
imgbb_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
56
57
// Copyright 2021 Wayback Archiver. All rights reserved.
// Use of this source code is governed by the GNU GPL v3
// license that can be found in the LICENSE file.
package imgbb // import "github.com/wabarc/imgbb"
import (
"image"
"image/color"
"image/png"
"os"
"testing"
)
func genImage(height int) *os.File {
width := 1000
upLeft := image.Point{0, 0}
lowRight := image.Point{width, height}
img := image.NewRGBA(image.Rectangle{upLeft, lowRight})
// Colors are defined by Red, Green, Blue, Alpha uint8 values.
cyan := color.RGBA{100, 200, 200, 0xff}
// Set color for each pixel.
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
switch {
case x < width/2 && y < height/2: // upper left quadrant
img.Set(x, y, cyan)
case x >= width/2 && y >= height/2: // lower right quadrant
img.Set(x, y, color.White)
default:
// Use zero value.
}
}
}
// Encode as PNG.
f, _ := os.Create(os.TempDir() + "/image.png")
png.Encode(f, img)
return f
}
func TestUploadByURI(t *testing.T) {
f := genImage(1024)
defer os.Remove(f.Name())
i := NewImgBB(nil, "")
if url, err := i.Upload(f.Name()); err != nil {
t.Fatal(err)
} else {
t.Log(url)
}
}