رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
تولید CAPTCHA راحت و قوی و قابل تنظیم
#1
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
<?php
  
// Configuration
$height = 75;
$width = 300;
$length = 6;
$lineCount = 25;
$circleCount = 25;
$maxRadius = 50;
$space = 40;
  
// Generate random code
session_start();
$alpha = array_merge(range('a', 'z'), range('0', '9'));
$string = '';
for($i = 0; $i < $length; $i++) {
    $string .= $alpha[rand() % count($alpha)];
}
$_SESSION['captcha'] = $string;
  
// Create image
header('Content-type: image/png');
$im = imagecreate($width, $height);
  
// Create colors
$backColor = imagecolorallocate($im, 255, 255, 255);
$textColor = imagecolorallocate($im, 0, 127, 255);
$lineColor = imagecolorallocate($im, 127, 191, 255);
  
// Assign font
$font = './Disney.ttf';
$fontsize = $height * 0.75;
  
// Calculate the bounding box of the text
$box = imagettfbbox($fontsize, 0, $font, $string);
  
// Start position of the text
$positionX = ($width - $space * $length) / 2;
  
// Rotation Direction (1: Anti-clockwise, -1: Clockwise)
$direction = 1;
  
// Fill the image with background color
imagefill($im, $width / 2, $height / 2, $backColor);
  
// Write the text in the image using font, rotation, position, etc.
for($i = 0; $i < $length; $i++) {
    $char = substr($string, $i, 1);
    imagettftext($im, $fontsize, (rand() % 30 * $direction), $positionX, ($height - $box[5]) / 2 - 2, $textColor,  $font, $char);
    $direction = -$direction;
    $positionX += $space;
}
  
// Add lines to the image
for($i = 0; $i < $lineCount; $i++) {
    $x1 = rand() % $width;
    $y1 = rand() % $height;
    $x2 = rand() % $width;
    $y2 = rand() % $height;
    imageline($im, $x1, $y1, $x2, $y2, $lineColor);
}
  
// Add circles to the image
for($i = 0; $i < $circleCount; $i++) {
    $cx = rand() % $width;
    $cy = rand() % $height;
    $rx = rand() % $maxRadius;
    $ry = rand() % $maxRadius;
    $start = rand() % 360;
    $end = rand() % 360;
    imagearc($im, $cx, $cy, $rx, $ry, $start, $end, $lineColor);
}
  
imagepng($im);
imagedestroy($im);
  
?>
پاسخ
تشکر شده توسط: php




کاربران در حال بازدید این موضوع: