forked from hanguofeng/gocaptcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagefilternoisepoint.go
45 lines (37 loc) · 995 Bytes
/
imagefilternoisepoint.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
// Copyright 2013 hanguofeng. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gocaptcha
import (
"strconv"
)
const IMAGE_FILTER_NOISE_POINT = "ImageFilterNoisePoint"
//ImageFilter is the interface of image filter
type ImageFilterNoisePoint struct {
ImageFilterBase
}
func imageFilterNoisePointCreator(config FilterConfigGroup) ImageFilter {
filter := ImageFilterNoisePoint{}
filter.SetConfig(config)
return &filter
}
//Proc the image
func (filter *ImageFilterNoisePoint) Proc(cimage *CImage) {
var num int
var err error
v, ok := filter.config.GetItem("Num")
if ok {
num, err = strconv.Atoi(v)
if nil != err {
num = 3
}
} else {
num = 3
}
for i := 0; i < num; i++ {
cimage.drawCircle(rnd(0, cimage.Bounds().Max.X), rnd(0, cimage.Bounds().Max.Y), rnd(0, 2), uint8(rnd(1, colorCount)))
}
}
func (filter *ImageFilterNoisePoint) GetId() string {
return IMAGE_FILTER_NOISE_POINT
}