Files
zurawik.pl/core/plugins/Captcha.php
2026-05-15 20:23:25 +02:00

112 lines
3.7 KiB
PHP

<?php
function put_char($char,$rgb,$posx,$posy) {
}
function confirm($string) {
$config = array(
'font'=>'arial.ttf', // font
'fontpath'=>PATH_CORE.'/plugins/', // polozenie pliku z fontem
'image'=>'captcha1.png', // nazwa obrazka typu PNG uzywanego jako background
'light'=>0, // jasnosc napisu, 100=bialy, 0=czarny
'saturation'=>90, // nasycenie koloru napisu, 0=szary, 100=najbardziej nasycony
'alpha'=>60, // przezroczystosc napisu, 0=bez przezroczystosci, 100=calkowicie transparentny
'imageheight'=>60,
'imagewidth'=>160
);
putenv('GDFONTPATH=' . realpath($config['fontpath']));
//$im = imagecreatefrompng($config['image']);
$im = imagecreatetruecolor($config['imagewidth'], $config['imageheight']);
if ($im) {
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, $config['imagewidth'], $config['imageheight'], $white);
$maxfontheight=$config['imageheight']*0.7;
$minfontheight=$config['imageheight']*0.4;
$px = ($config['imagewidth']-20)/(strlen($string));
header('Content-Type: image/png');
header('Cache-control: no-cache, no-store');
$textcolor=mt_rand(0, 359);
for ($i=0; $i<20; $i++) {
$rgb=hls2rgb(mt_rand($textcolor+20, $textcolor+319),60,$config['saturation']);
$color = imagecolorallocatealpha($im, $rgb[0], $rgb[1],$rgb[2],$config['alpha']);
$angle=mt_rand(-15, 15);
$fontheight=mt_rand($minfontheight/2, $minfontheight);
$posx=mt_rand(0, $config['imagewidth']);
$posy=mt_rand($fontheight, $config['imageheight']);
imagettftext( $im, $fontheight, $angle, $posx, $posy, $color, realpath($config['fontpath']).'/'.$config['font'], chr(mt_rand(ord('A'),ord('Z'))) );
}
$rgb=hls2rgb($textcolor,$config['light'],$config['saturation']);
$color = imagecolorallocatealpha($im, $rgb[0], $rgb[1],$rgb[2],$config['alpha']);
for ($i=0; $i<strlen($string); $i++) {
$angle=mt_rand(-15, 15);
$fontheight=mt_rand($minfontheight, $maxfontheight);
$posx=$i*$px+mt_rand(0, $px/4)+10;
$py = ($config['imageheight']+$fontheight)/2;
imagettftext( $im, $fontheight, $angle, $posx, $py, $color, realpath($config['fontpath']).'/'.$config['font'], $string[$i] );
}
for ($i=0; $i<20; $i++) {
$rgb=hls2rgb(mt_rand($textcolor+20, $textcolor+319),60,$config['saturation']);
$color = imagecolorallocatealpha($im, $rgb[0], $rgb[1],$rgb[2],$config['alpha']);
$angle=mt_rand(-15, 15);
$fontheight=mt_rand($minfontheight/2, $minfontheight);
$posx=mt_rand(0, $config['imagewidth']);
$posy=mt_rand($fontheight, $config['imageheight']);
imagettftext( $im, $fontheight, $angle, $posx, $posy, $color, realpath($config['fontpath']).'/'.$config['font'], chr(mt_rand(ord('A'),ord('Z'))) );
}
$color = imagecolorallocate($im, 0, 0,0);
imagepng($im);
imagedestroy($im);
}
else
die('Problem with file '.$config['image']);
}
function XRGB($hh, $mm1, $mm2) {
// funkcja pomocnicza
$hh=$hh%360;
if ($hh < 60)
return $mm1 + ($mm2 - $mm1) * $hh / 60;
elseif ($hh < 180)
return $mm2;
elseif ($hh < 240)
return $mm1 + ($mm2 - $mm1) * (240 - $hh) / 60;
else
return $mm1;
}
function hls2rgb($h,$l,$s) {
$il = ($l%100) / 100;
$ih = ($h%360);
$is = ($s%100) / 100;
if ($il <= 0.5)
$m2 = $il * (1 + $is);
else
$m2 = $il + $is - $il * $is;
$m1 = 2*$il - $m2;
if ($s == 0) {
$ir = $il;
$ig = $il;
$ib = $il;
}
else {
$ir = XRGB($ih + 120, $m1, $m2);
$ig = XRGB($ih , $m1, $m2);
$ib = XRGB($ih - 120, $m1, $m2);
}
return array(round($ir * 255),round($ig * 255),round($ib * 255));
}
?>