<?php

/* CONFIG */
$x	= 150;
$y	= 30;

$bgcol	= array(11, 11, 157);
$focol	= array(255, 255, 255);
$licol1	= array(150, 149, 243);
$licol2	= array(15, 85, 164);

$fontName = str_replace('capimg.php', 'garr66w.ttf', $_SERVER['SCRIPT_FILENAME']);



@session_start();

if ($_SESSION['pin_gen'] != '') {
	unset($_SESSION['pin_gen']);
}

function Code($anzahl) {
	$keychars = strtoupper('abcdefghkmnpqrstuvwxyz');
	$length = $anzahl;

	$randkey = '';
	$max = strlen($keychars) - 1;

	for ($i = 0; $i <= $length; ++$i) {
		$randkey .= substr($keychars, rand(0, $max), 1);
	}

	return $randkey;
}

$_SESSION['pin_gen'] = Code(4);

$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]);

$a = Code(7);

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 / 6 : $y / 2;

$posis = imagettfbbox($fontSize, 0, $fontName, $_SESSION['pin_gen']);

imagettftext($im, $fontSize, 0, ($x - $posis[2]) / 2, ($y - $posis[7]) / 2, $text_color, $fontName, $_SESSION['pin_gen']);

header("Content-type: image/png");
imagepng($im);

?>