112 lines
3.1 KiB
PHP
112 lines
3.1 KiB
PHP
<?php
|
|
/* simple-captcha, copyright rattatwinko 2026, license MIT
|
|
* captcha.php, captcha generator
|
|
* LICENSE AT END!
|
|
*/
|
|
session_start();
|
|
|
|
$chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
$code = substr(str_shuffle($chars), 0, 6);
|
|
$_SESSION['simple-captcha'] = $code;
|
|
|
|
$width = 220;
|
|
$height = 80;
|
|
|
|
$image = imagecreatetruecolor($width, $height);
|
|
|
|
$bg = imagecolorallocate($image, rand(220,255), rand(220,255), rand(220,255));
|
|
imagefilledrectangle($image, 0, 0, $width, $height, $bg);
|
|
|
|
// random text color
|
|
$textColor = imagecolorallocate($image, rand(0,100), rand(0,100), rand(0,100));
|
|
|
|
// noise lines
|
|
for ($i = 0; $i < 8; $i++) {
|
|
$noiseColor = imagecolorallocate($image, rand(100,180), rand(100,180), rand(100,180));
|
|
imageline(
|
|
$image,
|
|
rand(0,$width), rand(0,$height),
|
|
rand(0,$width), rand(0,$height),
|
|
$noiseColor
|
|
);
|
|
}
|
|
|
|
// noise dots
|
|
for ($i = 0; $i < 800; $i++) {
|
|
$dotColor = imagecolorallocate($image, rand(150,200), rand(150,200), rand(150,200));
|
|
imagesetpixel($image, rand(0,$width), rand(0,$height), $dotColor);
|
|
}
|
|
|
|
$font = __DIR__ . '/fonts/ComicRelief-Bold.ttf';
|
|
$x = 20;
|
|
|
|
for ($i = 0; $i < strlen($code); $i++) {
|
|
|
|
$angle = rand(-25, 25);
|
|
$y = rand(50, 65);
|
|
|
|
imagettftext(
|
|
$image,
|
|
rand(26, 32),
|
|
$angle,
|
|
$x,
|
|
$y,
|
|
$textColor,
|
|
$font,
|
|
$code[$i]
|
|
);
|
|
|
|
$x += 30;
|
|
}
|
|
|
|
imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
|
|
|
|
$distorted = imagecreatetruecolor($width, $height);
|
|
imagefill($distorted, 0, 0, $bg);
|
|
|
|
for ($x = 0; $x < $width; $x++) {
|
|
for ($y = 0; $y < $height; $y++) {
|
|
|
|
$newX = $x + (sin($y / 10) * 5);
|
|
$newY = $y + (sin($x / 15) * 5);
|
|
|
|
if ($newX >= 0 && $newX < $width && $newY >= 0 && $newY < $height) {
|
|
$color = imagecolorat($image, $newX, $newY);
|
|
imagesetpixel($distorted, $x, $y, $color);
|
|
}
|
|
}
|
|
}
|
|
|
|
header("Content-Type: image/png");
|
|
imagepng($distorted);
|
|
imagedestroy($image); // deprectated but who cares
|
|
imagedestroy($distorted); // also deprecated
|
|
|
|
|
|
/*
|
|
|
|
MIT License
|
|
|
|
Copyright (c) [2026] [rattatwinko]
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
*/
|
|
|
|
?>
|