Files

58 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2022-01-13 22:50:25 +01:00
<?php
2022-01-13 23:09:36 +01:00
// Martin Hozik
// 24.5.2008
// doublethink.cleverweb.cz
2022-01-13 22:50:25 +01:00
session_start();
2022-01-13 23:09:36 +01:00
// inicializace
2022-01-13 23:24:10 +01:00
require __DIR__ . '/imagelightnessat.func.php';
require __DIR__ . '/linear_perspective.class.php';
2022-01-13 22:50:25 +01:00
$perspective = new linear_perspective();
2022-01-13 23:09:36 +01:00
// konfigurace rozměrů a pozic
$matrix_dim = ['x' => 80, 'y' => 30];
$captcha_dim = ['x' => 300, 'y' => 90];
$distance = ['x' => 1, 'y' => 1, 'z' => 1];
$metric = ['x' => 10, 'y' => 20, 'z' => 5];
$offset = ['x' => 0, 'y' => -60];
2022-01-13 22:50:25 +01:00
2022-01-13 23:09:36 +01:00
// matrice
2022-01-13 22:50:25 +01:00
$matrix = imagecreatetruecolor($matrix_dim['x'], $matrix_dim['y']);
$black = imagecolorexact($matrix, 0, 0, 0);
$white = imagecolorexact($matrix, 255, 255, 255);
imagefill($matrix, 0, 0, $white);
2022-01-13 23:09:36 +01:00
// font calibri neni kvůli licenčním podmínkám připojen, použijte jakýkoliv svůj
2022-01-13 23:24:10 +01:00
imagefttext($matrix, 20, 0, 2, 25, $black, __DIR__ . '/3DCaptcha.ttf', $_SESSION['captcha']);
2022-01-13 22:50:25 +01:00
2022-01-13 23:09:36 +01:00
// výpočet bodů ve 3d
$point = [];
for ($x = 0; $x < $matrix_dim['x']; ++$x) {
for ($y = 0; $y < $matrix_dim['y']; ++$y) {
$lightness = imagelightnessat($matrix, $x, $y);
$point[$x][$y] = $perspective->get_projection(['x' => $x * $metric['x'] + $distance['x'], 'y' => $lightness * $metric['y'] + $distance['y'], 'z' => ($matrix_dim['y'] - $y) * $metric['z'] + $distance['z']]);
}
2022-01-13 22:50:25 +01:00
}
imagedestroy($matrix);
2022-01-13 23:09:36 +01:00
// obrázek captcha
2022-01-13 22:50:25 +01:00
$captcha = imagecreatetruecolor($captcha_dim['x'], $captcha_dim['y']);
2022-01-13 23:09:36 +01:00
// antialiasing čar - pro menší zátěž lze vypnout
2022-01-13 22:50:25 +01:00
//imageantialias($captcha, true);
$black = imagecolorexact($captcha, 255, 0, 0);
$white = imagecolorexact($captcha, 255, 255, 255);
imagefill($captcha, 0, 0, $white);
2022-01-13 23:09:36 +01:00
// vykreslení vrstevnic
for ($x = 1; $x < $matrix_dim['x']; ++$x) {
for ($y = 1; $y < $matrix_dim['y']; ++$y) {
imageline($captcha, -$point[$x - 1][$y - 1]['x'] + $offset['x'], -$point[$x - 1][$y - 1]['y'] + $offset['y'], -$point[$x][$y]['x'] + $offset['x'], -$point[$x][$y]['y'] + $offset['y'], $black);
}
2022-01-13 22:50:25 +01:00
}
2022-01-13 23:09:36 +01:00
// výstup
2022-01-13 22:50:25 +01:00
header('Content-type: image/png');
imagepng($captcha);