43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// Generate a random string
|
|
$permitted_chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ123456789';
|
|
$captcha_text = substr(str_shuffle($permitted_chars), 0, 5); // 5 characters for simplicity
|
|
$_SESSION['captcha'] = $captcha_text;
|
|
|
|
// Create image dimensions
|
|
$img_width = 140;
|
|
$img_height = 45;
|
|
|
|
// Create image
|
|
$image = imagecreatetruecolor($img_width, $img_height);
|
|
|
|
// Define minimalist colors
|
|
$bg_color = imagecolorallocate($image, 248, 250, 252); // Soft light background (#f8fafc)
|
|
$text_color = imagecolorallocate($image, 71, 85, 105); // Modern dark slate text (#475569)
|
|
$noise_color = imagecolorallocate($image, 203, 213, 225); // Subtle noise color (#cbd5e1)
|
|
|
|
// Fill background
|
|
imagefilledrectangle($image, 0, 0, $img_width, $img_height, $bg_color);
|
|
|
|
// Add minimal noise dots to avoid being completely plain, but very subtle
|
|
for ($i = 0; $i < 40; $i++) {
|
|
imagesetpixel($image, rand(0, $img_width), rand(0, $img_height), $noise_color);
|
|
}
|
|
|
|
// Add text to image with stable placement
|
|
$x = 22;
|
|
for ($i = 0; $i < strlen($captcha_text); $i++) {
|
|
$font_size = 5; // Largest built-in GD font
|
|
$y = rand(13, 16); // Very slight vertical variation for readability
|
|
|
|
imagechar($image, $font_size, $x, $y, $captcha_text[$i], $text_color);
|
|
$x += 20; // Consistent horizontal spacing
|
|
}
|
|
|
|
header('Content-type: image/png');
|
|
imagepng($image);
|
|
imagedestroy($image);
|
|
?>
|