-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaptchaImage.php
51 lines (42 loc) · 1.46 KB
/
captchaImage.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
<?php
require_once 'captchaCode.php';
class CaptchaImage
{
public $sum, $image, $black, $white, $random, $alt, $x;
public $dir = 'fonts/';
function __construct() {
}
public function image($numc, $code){
if($numc != ''){
$this->x = explode("a",$numc);
$this->sum = $this->x[0]." + ".$this->x[1];
}
else{
$this->sum = $code;
}
$this->image = imagecreatetruecolor(120, 50);
$this->black = imagecolorallocate($this->image, 0, 0, 0);
$this->white = imagecolorallocate($this->image, 255, 255, 255);
$this->random = imagecolorallocate($this->image, rand(1, 254), rand(1, 254), rand(1, 254));
imagefilledrectangle($this->image,0,0,200,100,$this->black);
for($i = 0; $i<200; $i++){
imagefilledellipse($this->image, mt_rand(0,120), mt_rand(0,50), 1, 1, $this->random);
}
for($i = 0; $i<10; $i++){
imageline($this->image, rand(1, 300), rand(1,200), rand(1,110), rand(1,90), $this->random);
imageline($this->image, rand(1, 90), rand(1,110), rand(1,200), rand(1,300), $this->random);
}
imagettftext($this->image, 20, 5, 10, 40, $this->white, $this->dir."arial.ttf", $this->sum);
header("Content-type: image/png");
imagepng($this->image);
imagedestroy($this->image);
}
}
if (isset($_GET['code']))
{
$code = $_GET['code'];
$numc = $_GET['numc'];
$captchaCode = new CaptchaImage();
$captchaCode->image($numc, $code);
}
?>