58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
|
|
// Martin Hozik
|
|
// 24.5.2008
|
|
// doublethink.cleverweb.cz
|
|
session_start();
|
|
// inicializace
|
|
require './imagelightnessat.func.php';
|
|
require './linear_perspective.class.php';
|
|
$perspective = new linear_perspective();
|
|
|
|
// 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];
|
|
|
|
// matrice
|
|
$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);
|
|
|
|
// font calibri neni kvůli licenčním podmínkám připojen, použijte jakýkoliv svůj
|
|
imagefttext($matrix, 20, 0, 2, 25, $black, './3DCaptcha.ttf', $_SESSION['captcha']);
|
|
|
|
// 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']]);
|
|
}
|
|
}
|
|
imagedestroy($matrix);
|
|
|
|
// obrázek captcha
|
|
$captcha = imagecreatetruecolor($captcha_dim['x'], $captcha_dim['y']);
|
|
|
|
// antialiasing čar - pro menší zátěž lze vypnout
|
|
//imageantialias($captcha, true);
|
|
|
|
$black = imagecolorexact($captcha, 255, 0, 0);
|
|
$white = imagecolorexact($captcha, 255, 255, 255);
|
|
imagefill($captcha, 0, 0, $white);
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
// výstup
|
|
header('Content-type: image/png');
|
|
imagepng($captcha);
|