Files
IdleRPG/irpg-web/captchaimage.php
2025-09-18 21:00:20 -06:00

51 lines
1.3 KiB
PHP

<?php
session_start();
// Create a blank image
$width = 52;
$height = 16;
$image = imagecreate($width, $height);
$backgroundColor = imagecolorallocate($image, 212, 255, 226);
imagefilledrectangle($image, 0, 0, $width, $height, $backgroundColor);
// Add some text
$captchaString = "";
$allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$charColor = imagecolorallocate($image, 64, 64, 64);
$numChars = 5;
for ($i=0; $i<$numChars; $i++)
{
$char = $allowedChars[rand(0, strlen($allowedChars)-1)];
imagestring($image, 5, 2+($i*10), 0, $char, $charColor);
$captchaString .= $char;
}
// Save the text to a session variable.
$_SESSION['captchaString'] = $captchaString;
// Add some lines
$lineColor = imagecolorallocate($image, 234, 132, 13);
$numLines = rand(2,2);
for($i=0; $i<$numLines; $i++)
{
imageline($image, 0, rand()%16, 52, rand()%16, $lineColor);
}
// Add some pixels
$pixelColor = imagecolorallocate($image, 11, 213, 142);
$numPixels = rand(38,40);
for($i=0; $i<$numPixels; $i++)
{
imagesetpixel($image, rand()%52, rand()%16, $pixelColor);
}
// Set the content type header - in this case image/jpeg
header('Content-type: image/jpeg');
// Output the image
imagejpeg($image);
// Free up memory
imagedestroy($image);
?>