
PK 
<?php
session_start();
// Create an image
$image = imagecreatetruecolor(200, 70);
// Colors
$bg = imagecolorallocate($image, rand(220, 255), rand(220, 255), rand(220, 255));
$text_color = imagecolorallocate($image, 0, 0, 0); // Black text for better visibility
// Fill background
imagefilledrectangle($image, 0, 0, 200, 70, $bg);
// Add some random colored shapes for background noise
for ($i = 0; $i < 10; $i++) {
$shape_color = imagecolorallocate($image, rand(180, 200), rand(180, 200), rand(180, 200));
$x1 = rand(0, 200);
$y1 = rand(0, 70);
$x2 = $x1 + rand(50, 100);
$y2 = $y1 + rand(20, 40);
imagefilledellipse($image, $x1, $y1, 30, 30, $shape_color);
}
// Generate random code
$chars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'; // Removed confusing characters like 1, I, 0, O
$length = 6;
$captcha_code = '';
for ($i = 0; $i < $length; $i++) {
$captcha_code .= substr($chars, rand(0, strlen($chars)-1), 1);
}
// Store code in session
$_SESSION['captcha_code'] = $captcha_code;
// Add text to image with built-in font (more reliable than TTF)
$font_size = 8; // Large built-in font
$char_width = imagefontwidth($font_size);
$total_width = $char_width * strlen($captcha_code);
$x = (200 - $total_width) / 2; // Center text horizontally
$y = 25;
// Draw each character with slight position variation
for ($i = 0; $i < strlen($captcha_code); $i++) {
$char_x = $x + ($i * ($char_width + 5)) + rand(-2, 2);
$char_y = $y + rand(-2, 2);
imagechar($image, $font_size, $char_x, $char_y, $captcha_code[$i], $text_color);
}
// Add random lines over text
for ($i = 0; $i < 3; $i++) {
$line_color = imagecolorallocate($image, rand(0, 150), rand(0, 150), rand(0, 150));
imageline($image, 0, rand(0, 70), 200, rand(0, 70), $line_color);
}
// Output image
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
?>


PK 99