forked from jaswdr/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.go
51 lines (45 loc) · 843 Bytes
/
image.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
package faker
import (
"image"
"image/color"
"image/png"
"io/ioutil"
"os"
)
type Image struct {
faker *Faker
}
func (i Image) Image(width, height int) *os.File {
upLeft := image.Point{0, 0}
lowRight := image.Point{width, height}
img := image.NewRGBA(image.Rectangle{upLeft, lowRight})
black := color.RGBA{0, 0, 0, 0xff}
white := color.RGBA{0xff, 0xff, 0xff, 0xff}
step := 4
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
if y > 0 {
if x%step == 0 {
if y%step == 0 {
img.Set(x, y, black)
} else {
img.Set(x, y, white)
}
} else {
img.Set(x, y, white)
}
} else {
img.Set(x, y, white)
}
}
}
f, err := ioutil.TempFile(os.TempDir(), "fake-img-*.png")
if err != nil {
panic(err)
}
err = png.Encode(f, img)
if err != nil {
panic(err)
}
return f
}