shop-old/libs/captcha/capimg_calculate.php
2026-04-20 01:03:43 +02:00

63 lines
1.3 KiB
PHP

<?php
@session_start();
/* CONFIG */
$x = 150;
$y = 30;
$bgcol = array(201, 199, 190);
$focol = array(0, 0, 0);
$licol1 = array(199, 20, 68);
$licol2 = array(153, 153, 153);
$fontName = str_replace('capimg_calculate.php', 'garr66w.ttf', $_SERVER['SCRIPT_FILENAME']);
if ($_SESSION['pin_gen3'] != '') {
unset($_SESSION['pin_gen3']);
}
function Code() {
$q[1] = rand(1, 10);
$q[2] = rand(1, 10);
$q[3] = $q[1] + $q[2];
return $q;
}
$a = Code();
$showCode = $a[1] . ' + ' . $a[2] . ' = ';
$_SESSION['pin_gen3'] = $a[3];
$im = @imagecreate($x, $y);
$background_color = imagecolorallocate($im, $bgcol[0], $bgcol[1], $bgcol[2]);
$text_color = imagecolorallocate($im, $focol[0], $focol[1], $focol[2]);
$licolor[0] = imagecolorallocate($im, $licol1[0], $licol1[1], $licol1[2]);
$licolor[1] = imagecolorallocate($im, $licol2[0], $licol2[1], $licol2[2]);
for ($i = 1; $i <= 15; ++$i) {
$lix = rand(0, $x);
$liy = rand(0, $y);
# imagesetthickness($im, rand(1, 5));
# imageline($im, $lax, $lay, $lix, $liy, $licolor[rand(0, 1)]);
$lax = $lix;
$lay = $liy;
}
$fontSize = ($x / 6 <= $y / 2) ? $x / 4 : $y / 1.2;
$posis = imagettfbbox($fontSize, 0, $fontName, $showCode);
imagettftext($im, $fontSize, 0, ($x - $posis[2]) / 2, ($y - $posis[7]) / 2, $text_color, $fontName, $showCode);
header("Content-type: image/png");
imagepng($im);
?>