-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcaptchaController.php
50 lines (39 loc) · 1.61 KB
/
captchaController.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
<?php
namespace App\Http\Controllers;
use Faker\Provider\Image;
use Illuminate\Http\Request;
class captchaController extends Controller
{
public function create()
{
$code = rand(10000, 99999);
session(['code' => $code]);
$width = 170;
$height = 60;
$image = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$gray = imagecolorallocate($image, 110, 110, 110);
$medgray = imagecolorallocate($image, 180, 180, 180);
$color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
imagefilledrectangle($image, 0, 0, $width , $height, $white);
$square_count = 6;
for ($i = 0; $i <$square_count; $i++) {
$cx = (int)rand(0, $width / 2);
$cy = (int)rand(0, $height);
$h = $cy + (int)rand(0, $height / 5);
$w = $cx + (int)rand($width / 3, $width);
imagefilledrectangle($image, $cx, $cy, $w, $h, $medgray);
}
$ellipse_count = 7;
for ($i = 0; $i < $ellipse_count; $i++) {
$cx = (int)rand(-1*($width/2), $width + ($width/2));
$cy = (int)rand(-1*($height/2), $height + ($height/2));
$h = (int)rand($height/2, 2*$height);
$w = (int)rand($width/2, 2*$width);
imageellipse($image, $cx, $cy, $w, $h, $gray);
}
imagettftext($image, 30, 0, 10, 40, $color, 'sahel/Sahel.ttf', $code);
return response((string)imagepng($image))->header('Content-Type', 'image/png');
}
}