/
image.class.php
89 lines (77 loc) · 2.39 KB
/
image.class.php
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
require_once 'imageTool.class.php';
class YImage {
private $Iresource;
private $white;
private $hight;
private $dataArray;
private $dataLenth;
public function __construct($Iresource) {
$this->Iresource = $Iresource;
$this->white = imagesx($this->Iresource);
$this->hight = imagesy($this->Iresource);
$this->dataLenth = $this->white * $this->hight;
}
/**
* 根据验证码的相同度判断是否为同一个
* @param type $dataArray
* @return boolean
*/
public function compare($dataArray) {
$tag = 0;
for ($x = 0; $x < $this->dataLenth; $x++) {
if ($this->dataArray[$x] == $dataArray[$x]) {
$tag++;
if ($tag >= $this->dataLenth-5)
return TRUE;
}
}
return FALSE;
}
/**
* 根据rgb去噪
* 原理是因为验证码和背景色的rgb不同
* @return image
*/
public function quzhao() {
$data = array();
for ($x = 0; $x < $this->white; $x++) {
for ($y = 0; $y < $this->hight; $y++) {
$index = ImageColorAt($this->Iresource, $x, $y);
$rgbarray = imagecolorsforindex($this->Iresource, $index);
if ($rgbarray['red'] < 78 || $rgbarray['green'] < 110 || $rgbarray['blue'] < 110) {
array_push($data, 1);
// echo "*";
} else {
array_push($data, 0);
imagefill($this->Iresource, $x, $y, self::getWhitePaint());
// echo "-";
}
// echo " ";
}
// echo " <br/>";
}
// echo "<br/>";
$this->dataArray = $data;
return $this->Iresource;
}
/**
* 白色画笔
* @return type
*/
public function getWhitePaint() {
return imagecolorallocate($this->Iresource, 0xFF, 0xFF, 0xFF);
}
public function getDataAray() {
return $this->dataArray;
}
public function getImage() {
return $this->Iresource;
}
public function save($path) {
YImageTool::save($this->Iresource, $path);
}
public function printImage() {
YImageTool::printImage($this->Iresource);
}
}