رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
تولید CAPTCHA راحت و قوی و قابل تنظیم
#1
<?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




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