30
function
getCaptcha()
31
{
32
return
$this
->code;
33
}
34
35
private
function
createImg()
36
{
37
$this
->im = imagecreatetruecolor(
$this
->width,
$this
->height);
38
$bgColor
= imagecolorallocate(
$this
->im, 0, 0, 0);
39
imagefill(
$this
->im, 0, 0,
$bgColor
);
40
}
41
42
private
function
setDisturb()
43
{
44
$area
= (
$this
->width *
$this
->height) / 20;
45
$disturbNum
= (
$area
> 250) ? 250 :
$area
;
46
//加入点干扰
47
for
(
$i
= 0;
$i
<
$disturbNum
;
$i
++) {
48
$color
= imagecolorallocate(
$this
->im,
rand
(0, 255),
rand
(0, 255),
rand
(0, 255));
49
imagesetpixel(
$this
->im,
rand
(1,
$this
->width - 2),
rand
(1,
$this
->height - 2),
$color
);
50
}
51
//加入弧线
52
for
(
$i
= 0;
$i
<= 5;
$i
++) {
53
$color
= imagecolorallocate(
$this
->im,
rand
(128, 255),
rand
(125, 255),
rand
(100,
255));
54
imagearc(
$this
->im,
rand
(0,
$this
->width),
rand
(0,
$this
->height),
rand
(30, 300),
rand
(20, 200), 50, 30,
$color
);
55
}
56
}
57
58
private
function
createCode()
59
{
60
$str
= "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ";
61
62
for
(
$i
= 0;
$i
<
$this
->codeNum;
$i
++) {
63
$this
->code .=
$str
{
rand
(0,
strlen
(
$str
) - 1)};
64
}
65
}