コード例 #1
0
<body>

<?php 
function generate_rand_string($length)
{
    $str = '';
    $small = "abcdefghijklmnopqrstuvwxyz";
    $possible = $small;
    $i = 0;
    while ($i < $length) {
        $str .= substr($possible, mt_rand(0, strlen($possible) - 1), 1);
        $i++;
    }
    return $str;
}
$text = generate_rand_string(6);
function dir_to_array($dir)
{
    $result = array();
    $cdir = scandir($dir);
    foreach ($cdir as $key => $value) {
        if (!in_array($value, array(".", ".."))) {
            if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) {
                $result[$value] = dir_to_array($dir . DIRECTORY_SEPARATOR . $value);
            } else {
                $result[] = $value;
            }
        }
    }
    return $result;
}
コード例 #2
0
 public function captcha_generator($text = false)
 {
     $input = \Request::all();
     $text = $text ? $text : generate_rand_string(6);
     $font = isset($input['font']) ? base_path("public/site-docs/captcha-fonts/" . $input['font']) : base_path("public/site-docs/captcha-fonts/COMICZ.TTF");
     $img_height = isset($input['height']) ? $input['height'] : 100;
     $img_width = isset($input['width']) ? $input['width'] : 200;
     $begin_point = $img_height / 2;
     header('Content-Type: image/png');
     $im = imagecreatetruecolor($img_width, $img_height);
     $background_color = imagecolorallocate($im, 40, 40, 40);
     $first_layer_color = imagecolorallocate($im, 100, 100, 100);
     $second_layer_color = imagecolorallocate($im, 200, 200, 200);
     $third_layer_color = imagecolorallocate($im, 250, 250, 250);
     imagefilledrectangle($im, 0, 0, $img_width, $img_height, $background_color);
     imagettftext($im, rand(30, 45), rand(-50, 50), rand(20, 40), rand($begin_point - 10, $begin_point + 10), $first_layer_color, $font, $text);
     imagettftext($im, 25, rand(-20, 20), rand(20, 40), rand($begin_point - 10, $begin_point + 10), $second_layer_color, $font, $text);
     imagettftext($im, 30, rand(-20, 20), rand(10, 30), rand($begin_point - 10, $begin_point + 10), $third_layer_color, $font, $text);
     imagepng($im);
     imagedestroy($im);
 }