// -------------------------------------------------
// ----- vytvoření obrázku a základní proměnné -----
// -------------------------------------------------
// ----- $zanky - obsahuje povolené znaky ----------
// ----- $delka - obsahuje délku kódu --------------
// ----- $kod - obsahuje vlasní kód ----------------
// ----- $cary - obsahuje počet matoucích čar ------
// -------------------------------------------------
$im = imagecreate(220, 40);
$font = "VeraMoBd.ttf";
$delka = 6;
$cary = 40;
$znaky = array ("A","B","C","1","2","3","4","5","6","7","8","9","0");
$kod = "";
// -------------------------------------------------
//--- vytvoření náhodného kódu ---------------------
// -------------------------------------------------
for ($i=0; $i<$delka; $i++) {
$kod .= $znaky[rand(0, count($znaky)-1)];
}
// -------------------------------------------------
// --- Vykreslení kódu do obrázku ------------------
// -------------------------------------------------
// --- využíván je náhodná velikost, úhel a barva --
// -------------------------------------------------
for ($i=0; $i<$delka; $i++) {
$font_size = rand(13, 17);
$uhel = rand(-30, 30);
$color_black = ImageColorAllocate($im, 0, 0, 0);
$color_background = ImageColorAllocate($im, 250, 250, 250);
$color_font = ImageColorAllocate($im, rand(0, 150), rand(0, 150), rand(0, 150));
imagefill($im,0,0,$color_background);
$rozmer = imagettfbbox($font_size, $uhel, $font, substr($kod,$i,1));
$sirka = abs($rozmer[2]-$rozmer[0]);
$vyska = abs($rozmer[5]-$rozmer[3]);
$x = (imagesx($im)/2)-($sirka/2)+(rand(-5, 5))+((-$delka/2+$i)*25);
$y = (imagesy($im))-($vyska/2);
ImageTTFText($im, $font_size, $uhel, $x, $y, $color_font, $font, substr($kod,$i,1));
}
//------------------------------------------------------------------
//---- Matoucí čáry ------------------------------------------------
//------------------------------------------------------------------
for ($i=0; $i< $cary; $i++) {
$x1=rand(5,imagesx($im) - 5);
$y1=rand(5,imagesy($im) - 5);
$x2=$x1+rand(0,30);
$y2=$y1+rand(0,30);
$color_cara = ImageColorAllocate($im, rand(0, 150), rand(0, 150), rand(0, 150));
imageline($im,$x1,$y1,$x2,$y2,$color_cara);
}
//------------------------------------------------------------------
//---- Nastavení výsttupního formátu - dle podpory PHP Serveru -----
//------------------------------------------------------------------
if (function_exists("imagegif")) {
header("Content-type: image/gif");
imagegif($im);
} elseif (function_exists("imagejpeg")) {
header("Content-type: image/jpeg");
imagejpeg($im, "", 0.5);
} elseif (function_exists("imagepng")) {
header("Content-type: image/png");
imagepng($im);
} elseif (function_exists("imagewbmp")) {
header("Content-type: image/vnd.wap.wbmp");
imagewbmp($im);
} else {
die("No image support in this PHP server");
}
imagedestroy($im);
?>
|