$font_arr = array(); $font_arr[0]["fname"] = "verdana.ttf"; //ttf шрифты, можно заменить на свои $font_arr[0]["size"] = 16; //размер $font_arr[1]["fname"] = "times.ttf"; //ttf шрифты, можно заменить на свои $font_arr[1]["size"] = 16; //размер $n = rand(0, sizeof($font_arr) - 1); $img_fn = $img_arr[rand(0, sizeof($img_arr) - 1)]; $im = imagecreatefrompng(code_dir . $img_fn); //создаем изображение со случайным фоном for ($i = 0; $i < $linenum; $i++) { //рисуем линии $color = imagecolorallocate($im, rand(0, 150), rand(0, 100), rand(0, 150)); imageline($im, rand(0, 20), rand(1, 50), rand(150, 180), rand(1, 50), $color); } $color = imagecolorallocate($im, rand(0, 200), 0, rand(0, 200)); imagettftext($im, $font_arr[$n]["size"], rand(-4, 4), rand(10, 45), rand(20, 35), $color, code_dir . $font_arr[$n]["fname"], generate_code()); //накладываем код for ($i = 0; $i < $linenum; $i++) { $color = imagecolorallocate($im, rand(0, 255), rand(0, 200), rand(0, 255)); imageline($im, rand(0, 20), rand(1, 50), rand(150, 180), rand(1, 50), $color); } ImagePNG($im); ImageDestroy($im); //ну вот и создано изображение! } img_code();
$sy = $y + (sin($x * $rand2 + $rand7) + sin($y * $rand4 + $rand8)) * $rand10; if ($sx < 0 || $sy < 0 || $sx >= $width - 1 || $sy >= $height - 1) { continue; } else { $color = imagecolorat($img, $sx, $sy) & 0xff; $color_x = imagecolorat($img, $sx + 1, $sy) & 0xff; $color_y = imagecolorat($img, $sx, $sy + 1) & 0xff; $color_xy = imagecolorat($img, $sx + 1, $sy + 1) & 0xff; } if ($color == 255 && $color_x == 255 && $color_y == 255 && $color_xy == 255) { continue; } else { if ($color == 0 && $color_x == 0 && $color_y == 0 && $color_xy == 0) { $newred = $foreground_color[0]; $newgreen = $foreground_color[1]; $newblue = $foreground_color[2]; } else { $newred = $ncolor[0]; $newgreen = $ncolor[1]; $newblue = $ncolor[2]; } } imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue)); imagecolortransparent($img2, imagecolorallocate($img2, 254, 254, 254)); } } return $img2; } $_SESSION['captchatime'] = time(); img_code($captcha);