Ejemplo n.º 1
0
 public function checkcode($width = 60, $height = 24, $verifyName = 'checkcode')
 {
     if (!isset($_SESSION)) {
         session_start();
     }
     $code = "ABCDEFGHKLMNPRSTUVWYZ23456789";
     $length = 4;
     $randval = '';
     for ($i = 0; $i < $length; $i++) {
         $char = $code[rand(0, strlen($code) - 1)];
         $randval .= $char;
     }
     $_SESSION[$verifyName] = strtolower($randval);
     $width = $length * 10 + 10 > $width ? $length * 10 + 10 : $width;
     $im = imagecreate($width, $height);
     $backColor = imagecolorallocate($im, 255, 255, 255);
     $borderColor = imagecolorallocate($im, 255, 255, 255);
     @imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
     @imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
     $fontcolor = imagecolorallocate($im, rand(0, 200), rand(0, 120), rand(0, 120));
     for ($i = 0; $i < $length; $i++) {
         $fontsize = 5;
         $x = floor($width / $length) * $i + 5;
         $y = rand(0, $height - 15);
         imagechar($im, $fontsize, $x, $y, $randval[$i], $fontcolor);
     }
     self::output($im, 'png');
 }
Ejemplo n.º 2
0
 /**
  * 显示验证码
  */
 public function render()
 {
     header('Pragma: no-cache');
     header('Cache-Control: no-cache');
     header('Content-Type: image/jpeg');
     $image = imagecreatetruecolor(79, 25);
     $color_Background = imagecolorallocate($image, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
     imagefill($image, 0, 0, $color_Background);
     $key = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'V', 'W', 'X', 'Y', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 't', 'v', 'w', 'x', 'y');
     $string = null;
     $char_X = mt_rand(1, 20);
     $char_Y = 0;
     for ($i = 0; $i < 4; $i++) {
         $char_Y = mt_rand(1, 6);
         $char = $key[mt_rand(0, 49)];
         $string .= $char;
         $color_Char = imagecolorallocate($image, mt_rand(20, 190), mt_rand(20, 190), mt_rand(20, 190));
         imagechar($image, 5, $char_X, $char_Y, $char, $color_Char);
         $char_X = $char_X + mt_rand(8, 20);
     }
     $this->_code = $string;
     $_SESSION[self::SESSION_KEY] = $string;
     imagegif($image);
     imagedestroy($image);
 }
Ejemplo n.º 3
0
 /**
  * generates the image for the captcha
  * @param string $name, used in the session
  * @param int $width
  * @param int $height
  * @param string $baseList
  */
 public static function image($name = '', $width = 120, $height = 40, $baseList = '123456789abcdfghjkmnpqrstvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ')
 {
     //echo $name.' orig= '.Session::instance()->get('captcha_'.$name).'<br>';
     $length = mt_rand(3, 5);
     //code length
     $lines = mt_rand(1, 5);
     //to make the image dirty
     $image = @imagecreate($width, $height) or die('Cannot initialize GD!');
     $code = '';
     //code generated saved at session
     //base image with dirty lines
     for ($i = 0; $i < $lines; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), imagecolorallocate($image, mt_rand(150, 255), mt_rand(150, 255), mt_rand(150, 255)));
     }
     //writting the chars
     for ($i = 0, $x = 0; $i < $length; $i++) {
         $actChar = substr($baseList, rand(0, strlen($baseList) - 1), 1);
         $x += 10 + mt_rand(0, 10);
         imagechar($image, mt_rand(4, 5), $x, mt_rand(5, 20), $actChar, imagecolorallocate($image, mt_rand(0, 155), mt_rand(0, 155), mt_rand(0, 155)));
         $code .= strtolower($actChar);
     }
     Session::instance()->set('captcha_' . $name, $code);
     //die( 'changed= '.Session::instance()->get('captcha_'.$name));
     // prevent client side caching
     header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Cache-Control: post-check=0, pre-check=0", FALSE);
     header("Pragma: no-cache");
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
 }
Ejemplo n.º 4
0
function create_captha_img($char)
{
    $width = 100;
    $height = 25;
    $im = @imagecreate($width, $height) or die("Cannot initialize new GD image stream!");
    $char = str_replace(array('a', 'b', 'c', 'd', 'e', 'f'), array('1', '5', '8', '2', '7', '9'), $char);
    $char = substr($char, 1, 4);
    imagecolortransparent($im, imagecolorallocate($im, 205, 255, 255));
    for ($i = 0; $i < strlen($char); $i++) {
        $text_color = imagecolorallocate($im, rand(200, 255), rand(0, 120), rand(0, 120));
        $x = $width / 10 + $i * ($width / 5);
        $y = 0;
        imagechar($im, 4, $x, $y, chr(rand(65, 90)), $text_color);
    }
    imageline($im, 1, rand(5, 10), $width - 10, rand(5, 10), imagecolorallocatealpha($im, rand(180, 255), rand(0, 120), rand(0, 120), 60));
    for ($i = 0; $i < strlen($char); $i++) {
        $text_color = imagecolorallocate($im, rand(0, 180), rand(0, 180), rand(0, 180));
        $x = rand(0, 5) + $i * $width / rand(4, 5);
        $y = rand(8, 12);
        imagechar($im, 5, $x, $y, $char[$i], $text_color);
    }
    ob_start();
    imagepng($im);
    $src = 'data:image/png;base64,' . base64_encode(ob_get_contents());
    ob_end_clean();
    imagedestroy($im);
    return $src;
}
Ejemplo n.º 5
0
function verify_code()
{
    $randCode = '';
    $chars = 'abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPRSTUVWXYZ23456789';
    for ($i = 0; $i < 5; $i++) {
        $randCode .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
    }
    $img = imagecreate(70, 22);
    $bgColor = imagecolorallocate($img, 255, 255, 255);
    $pixColor = imagecolorallocate($img, mt_rand(30, 180), mt_rand(10, 100), mt_rand(40, 250));
    for ($i = 0; $i < 5; $i++) {
        $x = $i * 13 + mt_rand(0, 4) - 2;
        $y = mt_rand(0, 3);
        $text_color = imagecolorallocate($img, mt_rand(30, 180), mt_rand(10, 100), mt_rand(40, 250));
        imagechar($img, 5, $x + 5, $y + 3, $randCode[$i], $text_color);
    }
    for ($j = 0; $j < 60; $j++) {
        $x = mt_rand(0, 70);
        $y = mt_rand(0, 22);
        imagesetpixel($img, $x, $y, $pixColor);
    }
    $_SESSION['code'] = $randCode;
    header('Content-Type: image/png');
    imagepng($img);
    imagedestroy($img);
}
Ejemplo n.º 6
0
 /**
  * 生成验证码
  * @param int $width 验证码图片宽度.默认130
  * @param int $height 验证码图片高度.默认40
  * @param int $fontSize 验证码字体大小.默认20
  * @param int $length 验证码字符个数.默认4
  * @return string  验证码中的字符串
  */
 public static function getCaptcha($width = '130', $height = '40', $fontSize = '20', $length = '4')
 {
     $chars = '0123456789abcdefghijklmnopqrstuvwxyz';
     $randStr = substr(str_shuffle($chars), 0, $length);
     $image = imagecreatetruecolor($width, $height);
     // 定义背景色
     $bgColor = imagecolorallocate($image, 0xff, 0xff, 0xff);
     // 定义文字及边框颜色
     $blackColor = imagecolorallocate($image, 0x0, 0x0, 0x0);
     //生成矩形边框
     imagefilledrectangle($image, 0, 0, $width, $height, $bgColor);
     // 循环生成雪花点
     for ($i = 0; $i < 200; $i++) {
         $grayColor = imagecolorallocate($image, 128 + rand(0, 128), 128 + rand(0, 128), 128 + rand(0, 128));
         imagesetpixel($image, rand(1, $width - 2), rand(4, $height - 2), $grayColor);
     }
     $font = ROOT_PATH . 'resources/fonts/acidic.ttf';
     // 把随机字符串输入图片
     $i = -1;
     while (isset($randStr[++$i])) {
         $fontColor = imagecolorallocate($image, rand(0, 100), rand(0, 100), rand(0, 100));
         if (!function_exists('imagettftext')) {
             imagechar($image, $fontSize, 15 + $i * 30, rand(5, 20), $randStr[$i], $fontColor);
         } else {
             imagettftext($image, $fontSize, 0, 10 + $i * 30, rand(25, 35), $fontColor, $font, $randStr[$i]);
         }
     }
     imagepng($image);
     $image = $bgColor = $blackColor = $grayColor = $fontColor = null;
     return $randStr;
 }
Ejemplo n.º 7
0
 public static function newVerify($width = 60, $height = 25)
 {
     $im = imagecreate($width, $height);
     $backgroundcolor = imagecolorallocate($im, 255, 255, 255);
     $mCheckCodeNum = 4;
     $mCheckCode = '';
     for ($i = 0; $i < $mCheckCodeNum; $i++) {
         $mCheckCode .= strtoupper(chr(rand(97, 122)));
     }
     $session = new XF_Session('XF_ImageVerify');
     $session->write(strtolower($mCheckCode));
     for ($i = 0; $i <= 64; $i++) {
         $pointcolor = imagecolorallocate($im, mt_rand(1, 155), mt_rand(0, 200), mt_rand(1, 155));
         imagesetpixel($im, mt_rand(0, $width - 1), mt_rand(0, $height - 1), $pointcolor);
     }
     $snowflake_size = 5;
     for ($i = 0; $i < $mCheckCodeNum; $i++) {
         $font_color = imagecolorallocate($im, mt_rand(1, 155), mt_rand(1, 200), 100);
         $x = floor($width / $mCheckCodeNum) * $i + 3;
         $y = rand(0, $height - 15);
         imagechar($im, $snowflake_size, $x, $y, $mCheckCode[$i], $font_color);
     }
     $bordercolor = imagecolorallocate($im, 188, 188, 188);
     imagerectangle($im, 0, 0, $width - 1, $height - 1, $bordercolor);
     header('Content-type: image/png');
     imagepng($im);
     imagedestroy($im);
 }
Ejemplo n.º 8
0
 private function writeCheckCodeToImage()
 {
     for ($i = 0; $i <= $this->codenum; $i++) {
         $bg_color = imagecolorallocate($this->checkimage, rand(0, 255), rand(0, 128), rand(0, 255));
         $x = floor($this->width / $this->codenum) * $i + 2;
         $y = rand(1, $this->height - 15);
         imagechar($this->checkimage, rand(5, 8), $x, $y, $this->checkcode[$i], $bg_color);
     }
 }
Ejemplo n.º 9
0
 /**
  * @write code to Image
  */
 function WriteCheckCodeToImage()
 {
     for ($i = 0; $i <= $this->mCheckCodeNum; $i++) {
         $bg_color = imagecolorallocate($this->mCheckImage, rand(0, 255), rand(0, 128), rand(0, 255));
         $x = floor($this->mCheckImageWidth / $this->mCheckCodeNum) * $i;
         $y = rand(0, $this->mCheckImageHeight - 15);
         imagechar($this->mCheckImage, 5, $x, $y, $this->mCheckCode[$i], $bg_color);
     }
 }
Ejemplo n.º 10
0
 private function outputtext()
 {
     for ($i = 0; $i < $this->codeNum; $i++) {
         $fontcolor = imagecolorallocate($this->image, rand(0, 128), rand(0, 128), rand(0, 128));
         $fontsize = rand(3, 5);
         $x = floor($this->width / $this->codeNum) * $i + 3;
         $y = rand(0, $this->height - imagefontheight($fontsize));
         imagechar($this->image, $fontsize, $x, $y, $this->checkcode[$i], $fontcolor);
     }
 }
Ejemplo n.º 11
0
 private function outputText()
 {
     for ($i = 0; $i <= $this->codeNum; $i++) {
         $bg_color = imagecolorallocate($this->image, mt_rand(0, 255), mt_rand(0, 128), mt_rand(0, 255));
         $x = floor($this->width / $this->codeNum) * $i + 3;
         $y = mt_rand(0, $this->height - 15);
         $str = substr($this->checkCode, $i, 1);
         imagechar($this->image, 5, $x, $y, $str, $bg_color);
     }
 }
Ejemplo n.º 12
0
 private function setCaptcha()
 {
     for ($i = 0; $i < $this->codeNum; $i++) {
         $color = imagecolorallocate($this->im, rand(50, 250), rand(100, 250), rand(128, 250));
         $size = rand(floor($this->height / 5), floor($this->height / 3));
         $x = floor($this->width / $this->codeNum) * $i + 5;
         $y = rand(0, $this->height - 20);
         imagechar($this->im, $size, $x, $y, $this->code[$i], $color);
     }
 }
Ejemplo n.º 13
0
 private function outputText()
 {
     for ($i = 0; $i < $this->codeNum; $i++) {
         $bg_color = imagecolorallocate($this->image, rand(0, 255), rand(0, 128), rand(0, 255));
         $x = floor($this->width / $this->codeNum) * $i + 3;
         $y = rand(0, $this->height - 15);
         //echo $this->checkCode;
         imagechar($this->image, 5, $x, $y, $this->checkCode[$i], $bg_color);
     }
 }
Ejemplo n.º 14
0
 private function outstring()
 {
     for ($i = 0; $i < $this->num; $i++) {
         $color = imagecolorallocate($this->img, rand(0, 128), rand(0, 128), rand(0, 128));
         $fontsize = rand(3, 5);
         $x = 3 + $this->width / $this->num * $i;
         $y = rand(0, imagefontheight($fontsize) - 3);
         imagechar($this->img, $fontsize, $x, $y, $this->code[$i], $color);
     }
 }
Ejemplo n.º 15
0
 private function drawCode()
 {
     for ($i = 0; $i < $this->codeLen; $i++) {
         $color = imagecolorallocate($this->img, mt_rand(0, 128), mt_rand(0, 128), mt_rand(0, 128));
         $fontsize = mt_rand(5, 8);
         $x = 3 + $this->codeWidth / $this->codeLen * $i;
         $y = rand(2, imagefontheight($fontsize) - 10);
         imagechar($this->img, $fontsize, $x, $y, $this->code[$i], $color);
     }
     return;
 }
Ejemplo n.º 16
0
 private function setCaptcha()
 {
     $this->createCode();
     for ($i = 0; $i < $this->codeNum; $i++) {
         $color = imagecolorallocate($this->im, hexdec(substr($this->fontColor, 1, 2)), hexdec(substr($this->fontColor, 3, 2)), hexdec(substr($this->fontColor, 5, 2)));
         $size = rand(floor($this->height / 5), floor($this->height / 3));
         $x = floor($this->width / $this->codeNum) * $i + 5;
         $y = rand(0, $this->height - 20);
         imagechar($this->im, $size, $x, $y, $this->code[$i], $color);
     }
 }
Ejemplo n.º 17
0
/**
 * MaxSite CMS
 * (c) http://max-3000.com/
 */
function _create_captha_img()
{
    $width = 100;
    $height = 25;
    $im = @imagecreate($width, $height) or die("Cannot initialize new GD image stream!");
    if (isset($_GET['image']) and isset($_GET['page'])) {
        $char = md5($_GET['image'] . $_GET['page']);
    } else {
        die("error");
    }
    $char = str_replace(array('a', 'b', 'c', 'd', 'e', 'f'), array('0', '5', '8', '3', '4', '7'), $char);
    $char = substr($char, 1, 4);
    imagecolortransparent($im, imagecolorallocate($im, 205, 255, 255));
    // rnd
    for ($i = 0; $i < strlen($char); $i++) {
        // $text_color = imagecolorallocate ($im, rand(220,255), rand(0,40), 120);
        $text_color = imagecolorallocate($im, 255, 0, 0);
        $x = $width / 10 + $i * ($width / 5);
        // $y = rand(0, 5);
        $y = 0;
        imagechar($im, 4, $x, $y, chr(rand(49, 90)), $text_color);
    }
    $point_color = imagecolorallocate($im, 255, 120, 120);
    ImageLine($im, 3, 9, 150, 2, $point_color);
    //output characters
    for ($i = 0; $i < strlen($char); $i++) {
        $text_color = imagecolorallocate($im, rand(0, 120), rand(0, 180), rand(0, 180));
        // $x = 5 + $i * 40 + rand(-5, 5);
        $x = 3 + $i * $width / 4;
        //$y = rand(0, 5);
        $y = 10;
        imagechar($im, 5, $x, $y, $char[$i], $text_color);
    }
    //ouput PNG
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    // HTTP/1.1
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    //	HTTP/1.0
    if (function_exists("imagepng")) {
        header("Content-type: image/png");
        imagepng($im);
    } elseif (function_exists("imagegif")) {
        header("Content-type: image/gif");
        imagegif($im);
    } elseif (function_exists("imagejpeg")) {
        header("Content-type: image/jpeg");
        imagejpeg($im);
    } else {
        die("No image support in this PHP server!");
    }
    imagedestroy($im);
}
Ejemplo n.º 18
0
 private function setCaptcha()
 {
     $this->createCode();
     $changdu = strlen($this->codeNum);
     for ($i = 0; $i < $changdu; $i++) {
         $color = imagecolorallocate($this->im, 250, 0, 0);
         // $size = rand(floor($this->height / 5), floor($this->height / 3));
         $x = floor($this->width / $changdu) * $i + 5;
         $y = rand(0, $this->height - 20);
         imagechar($this->im, 5, $x, $y, $this->code[$i], $color);
     }
 }
Ejemplo n.º 19
0
 private function setCaptcha()
 {
     $this->createCode();
     $tCode = '';
     for ($i = 0; $i < $this->codeNum; $i++) {
         $color = imagecolorallocate($this->im, rand(200, 250), rand(200, 250), rand(228, 250));
         $size = rand(floor($this->height / 5), floor($this->height / 3));
         $x = floor($this->width / $this->codeNum) * $i + 5;
         $y = rand(0, $this->height - 20);
         imagechar($this->im, $size, $x, $y, $this->code[$i], $color);
         $tCode .= $this->code[$i];
     }
     $_SESSION['captcha'] = $tCode;
 }
Ejemplo n.º 20
0
function yzm($width = 100, $height = 40, $length = 4, $type = 3, $imageType = 'jpeg')
{
    switch ($type) {
        case 1:
            $str = join('', array_rand(range(0, 9), 4));
            break;
        case 2:
            $str = join('', array_rand(array_flip(range(a, z)), 4));
            break;
        case 3:
            $str = '';
            for ($i = 0; $i < 4; $i++) {
                $sj = mt_rand(0, 2);
                switch ($sj) {
                    case 0:
                        $char = mt_rand(0, 9);
                        break;
                    case 1:
                        $char = array_rand(array_flip(range('a', 'z')), 1);
                        break;
                    case 2:
                        $char = array_rand(array_flip(range('A', 'Z')), 1);
                        break;
                }
                $str .= $char;
            }
            break;
    }
    //echo $str;  不可以输出
    $_SESSION['yzm'] = $str;
    $img = imagecreate($width, $height);
    imagefilledrectangle($img, 0, 0, $width, $height, qianys($img));
    //干扰元素,像素点
    for ($i = 0; $i < 50; $i++) {
        imagesetpixel($img, mt_rand(1, $width), mt_rand(1, $height), shenys($img));
    }
    //干扰元素,线段
    for ($i = 0; $i < 4; $i++) {
        imageline($img, mt_rand(1, $width), mt_rand(1, $height), mt_rand(1, $width), mt_rand(1, $height), shenys($img));
    }
    //写字
    for ($i = 0; $i < 4; $i++) {
        imagechar($img, 5, mt_rand(25 * $i, 22 * ($i + 1)), mt_rand(1, 25), $str[$i], shenys($img));
    }
    //输出
    header('Content-Type:image/jpeg');
    imagejpeg($img);
    //关闭资源
    imagedestroy($img);
}
Ejemplo n.º 21
0
function authcode($len = 4, $width = "50", $height = 25, $codetype = "png", $code_type = "3")
{
    if ($code_type == 3) {
        $strs = random($len);
    } else {
        if ($code_type == 2) {
            $strs = random_language($len);
        } else {
            $strs = random_shuzi($len);
        }
    }
    $width = $width;
    $height = $height;
    if ($codetype == "png") {
        @header("Content-Type:image/png");
    } elseif ($codetype == "jpg") {
        @header("Content-Type:image/jpeg");
    } else {
        @header("Content-Type:image/gif");
    }
    $im = imagecreate($width, $height);
    $back = imagecolorallocate($im, 255, 255, 255);
    imagefill($im, 0, 0, $back);
    $pix = imagecolorallocate($im, 222, 222, 222);
    $border_color = imagecolorallocate($im, 234, 234, 234);
    $black = imagecolorallocate($im, 0, 0, 0);
    $gray = imagecolorallocate($im, 200, 200, 200);
    mt_srand();
    for ($i = 0; $i < 100; $i++) {
        imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $pix);
    }
    $font_size = 20;
    $x = rand(2, 5);
    for ($i = 0; $i < $len; $i++) {
        if ($i == 0) {
            $xx = $x;
        } else {
            $xx = $x + $font_size - 1 + rand(0, 1);
        }
        $text_color = imagecolorallocate($im, rand(50, 180), rand(0, 180), rand(100, 180));
        imagechar($im, 5, $xx, rand(1, 15), $strs[$i], $text_color);
        $x = $xx;
    }
    imagerectangle($im, 0, 0, $width - 1, $height - 1, $border_color);
    imagepng($im);
    imagedestroy($im);
    $strs = md5(strtolower($strs));
    $_SESSION["authcode"] = $strs;
}
Ejemplo n.º 22
0
 function G($width = 100, $heiht = 37)
 {
     mt_srand((double) microtime() * 1000000);
     if ($this->number) {
         $hash = sprintf('%0' . $this->length . 'd', mt_rand(0, pow(10, $this->length) - 1));
     } else {
         $hash = '';
         $chars = 'ABCDEQRSTUVWXYZ23456FGHIJKLMNP789';
         $max = strlen($chars) - 1;
         for ($i = 0; $i < $this->length; $i++) {
             $hash .= $chars[mt_rand(0, $max)];
         }
     }
     $this->session->set_userdata('validecode', strtolower($hash));
     $im = imagecreate($width, $heiht);
     $backgroundcolor = imagecolorallocate($im, 255, 255, 255);
     $numorder = array(1, 2, 3, 4);
     shuffle($numorder);
     $numorder = array_flip($numorder);
     for ($i = 1; $i <= 4; $i++) {
         $x = $numorder[$i] * 20 + mt_rand(0, 4) - 2;
         $y = mt_rand(2, 12);
         $text_color = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 128), mt_rand(50, 255));
         imagechar($im, 5, $x + 12, $y, $hash[$numorder[$i]], $text_color);
     }
     $linenums = mt_rand(10, 32);
     for ($i = 0; $i < 4; $i++) {
         $color1 = ImageColorAllocate($im, mt_rand(100, 255), mt_rand(100, 255), mt_rand(100, 255));
         ImageArc($im, mt_rand(-5, $width), mt_rand(-5, $heiht), mt_rand(30, $width), mt_rand(30, $heiht), 55, 44, $color1);
     }
     for ($i = 0; $i <= $linenums; $i++) {
         $linecolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         $linex = mt_rand(0, $width - 2);
         $liney = mt_rand(0, $heiht - 2);
         imageline($im, $linex, $liney, $linex + mt_rand(0, 4) - 2, $liney + mt_rand(0, 4) - 2, $linecolor);
     }
     for ($i = 0; $i <= $width - 2; $i++) {
         $pointcolor = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 255), mt_rand(50, 255));
         imagesetpixel($im, mt_rand(0, $width - 2), mt_rand(0, $heiht - 2), $pointcolor);
     }
     $bordercolor = imagecolorallocate($im, 150, 150, 150);
     imagerectangle($im, 0, 0, $width - 2, $heiht - 2, $bordercolor);
     header('Content-type: image/png');
     imagepng($im);
     imagedestroy($im);
 }
Ejemplo n.º 23
0
 public function putimg($code)
 {
     $img = imagecreatetruecolor($this->width, $this->height);
     $background = imagecolorallocate($img, 255, 255, 255);
     imagefill($img, 0, 0, $background);
     $color = imagecolorallocate($img, 0, 0, 0);
     $n = rand(5, 10);
     for ($i = 0; $i < $n; $i++) {
         $x = rand(0, $this->width - 6);
         $y = rand(0, $this->height - 6);
         for ($j = 0; $j < 12; $j++) {
             imagesetpixel($img, $x + rand(0, 1), $y + rand(0, 1), $color);
         }
     }
     $n = rand(0, 1);
     for ($i = 0; $i < $n; $i++) {
         $cx = rand(5, $this->width);
         $cy = rand(0, 2) * $i;
         $w = rand($this->width, $this->width * 3);
         $h = rand(floor($this->height / 2), $this->height);
         imagearc($img, $cx, $cy, $w, $h, 90, 270, $color);
     }
     $len = strlen($code);
     for ($i = 0; $i < $len; $i++) {
         $size = rand(8, 15);
         $x = floor($this->width / $len) * $i + rand(2, 6);
         $y = rand(1, $this->height - 16);
         imagechar($img, $size, $x, $y, $code[$i], $color);
     }
     $n = rand(1, 3);
     switch ($n) {
         case 1:
             header('Content-type:image/jpeg');
             imagejpeg($img);
             break;
         case 2:
             header('Content-type:image/gif');
             imagegif($img);
             break;
         case 3:
             header('Content-type:image/png');
             imagepng($img);
             break;
     }
     imagedestroy($img);
 }
 private function outputText($fontFace = "")
 {
     for ($i = 0; $i < $this->codeNum; $i++) {
         $fontcolor = imagecolorallocate($this->image, rand(0, 128), rand(0, 128), rand(0, 128));
         if ($fontFace == "") {
             $fontsize = rand(3, 5);
             $x = floor($this->width / $this->codeNum) * $i + 3;
             $y = rand(0, $this->height - 15);
             imagechar($this->image, $fontsize, $x, $y, $this->checkCode[$i], $fontcolor);
         } else {
             $fontsize = rand(12, 16);
             $x = floor(($this->width - 8) / $this->codeNum) * $i + 8;
             $y = rand($fontSize + 5, $this->height);
             imagettftext($this->image, $fontsize, rand(-30, 30), $x, $y, $fontcolor, $fontFace, $this->checkCode[$i]);
         }
     }
 }
Ejemplo n.º 25
0
 protected function create()
 {
     $num = 4;
     //验证码个数
     $width = 80;
     //验证码宽度
     $height = 20;
     //验证码高度
     $code = ' ';
     //生成验证码
     for ($i = 0; $i < $num; $i++) {
         switch (rand(0, 2)) {
             //数字
             case 0:
                 $code[$i] = chr(rand(48, 57));
                 break;
                 //大写字母
             //大写字母
             case 1:
                 $code[$i] = chr(rand(65, 90));
                 break;
                 //小写字母
             //小写字母
             case 2:
                 $code[$i] = chr(rand(97, 122));
                 break;
         }
     }
     $_SESSION["SecurityCode"] = $code;
     $image = imagecreate($width, $height);
     imagecolorallocate($image, 255, 255, 255);
     //生成干扰像素
     for ($i = 0; $i < 80; $i++) {
         $dis_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
         imagesetpixel($image, rand(1, $width), rand(1, $height), $dis_color);
     }
     //打印字符到图像
     for ($i = 0; $i < $num; $i++) {
         $char_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
         imagechar($image, 60, $width / $num * $i, rand(0, 5), $code[$i], $char_color);
     }
     header("Content-type:image/png");
     imagepng($image);
     imagedestroy($image);
 }
Ejemplo n.º 26
0
		public function veryCode()
		{
			
			$image=imagecreate($this->width,$this->height);
			imagecolorallocate($image,255,255,255);
			//$this->genOther($image);
			
			$num = 4;
			$code = $this->genCode($num);
			for($i=0;$i<$num;$i++)//打印字符到图像
			{
				$char_color=imagecolorallocate($image,rand(0,2555),rand(0,255),rand(0,255));
				imagechar($image,60,($this->width/$num)*$i,rand(0,5),$code[$i],$char_color);
			}
			
			header("Content-type:image/png");
			imagepng($image);//输出图像到浏览器
			imagedestroy($image);//释放资源
		}
Ejemplo n.º 27
0
 public function build()
 {
     //生成图像
     if (!isset($_SESSION)) {
         session_start();
     }
     switch ($this->type) {
         case 10:
             $char = array_slice($this->chars, 0, 10);
             break;
         case 26:
             $char = array_slice($this->chars, 10);
             break;
         default:
             $char = $this->chars;
     }
     $str = "";
     for ($i = 0; $i < $this->number; $i++) {
         $str .= $char[array_rand($char)];
     }
     $im = imagecreatetruecolor($this->width, $this->height);
     $bgcolor = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250));
     imagefill($im, 0, 0, $bgcolor);
     for ($i = 0; $i < $this->dots; $i++) {
         imagesetpixel($im, rand(0, $this->width), rand(0, $this->height), imagecolorallocate($im, rand(120, 200), rand(120, 200), rand(120, 200)));
     }
     for ($i = 0; $i < $this->lines; $i++) {
         $x1 = rand(0, $this->width);
         $x2 = rand(0, $this->width);
         $y1 = rand(0, $this->height);
         $y2 = rand(0, $this->height);
         imageline($im, min($x1, $x2), min($y1, $y2), max($x1, $x2), max($y1, $y2), imagecolorallocate($im, rand(100, 220), rand(100, 220), rand(100, 220)));
     }
     $_SESSION['verify_code'] = strtolower($str);
     for ($i = 0; $i < $this->number; $i++) {
         imagechar($im, $this->size, $i * 20 + 5, rand(0, 10), $str[$i], imagecolorallocate($im, rand(0, 150), rand(0, 150), rand(0, 150)));
     }
     imagepng($im);
     imagedestroy($im);
 }
Ejemplo n.º 28
0
 public function achieveImage()
 {
     $image = imagecreate($this->width, $this->height);
     $background = imagecolorallocate($image, 255, 255, 255);
     $fontcolor = imagecolorallocate($image, 0, 0, 0);
     imagerectangle($image, 0, 0, $this->width - 1, $this->height - 1, $fontcolor);
     for ($i = 0; $i < 120; $i++) {
         $color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
         imagesetpixel($image, rand(0, $this->width), rand(0, $this->height), $color);
     }
     for ($i = 0; $i < 5; $i++) {
         $color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
         imagearc($image, rand(-15, $this->width), rand(-20, $this->height), rand(30, 100), rand(20, 100), 10, 100, $color);
     }
     $char = str_split($this->vCodeString);
     $distance = $this->width / ($this->bitNum + 1);
     for ($i = 0; $i < $this->bitNum; $i++) {
         imagechar($image, 5, $i * $distance + 5, 2, $char[$i], $fontcolor);
     }
     imagepng($image);
     imagedestroy($image);
 }
Ejemplo n.º 29
0
 function showimage($randstr)
 {
     //设置字体大小
     $font_size = 26;
     $len = strlen($randstr);
     $imstr = array();
     for ($i = 0; $i < $len; $i++) {
         $imstr[$i] = array('c' => $randstr[$i], 'x' => 12 * $i + rand(0, 6), 'y' => rand(0, 20));
     }
     $imageY = $len * 10 + 10;
     $im = @imagecreatetruecolor($imageY, $font_size + 8) or die("建立图像失败");
     //获取背景颜色
     $background_color = imagecolorallocate($im, 255, 255, 255);
     //填充背景颜色(这个东西类似油桶)
     imagefill($im, 0, 0, $background_color);
     //获取边框颜色
     $border_color = imagecolorallocate($im, 180, 180, 180);
     //画矩形,边框颜色200,200,200
     imagerectangle($im, 0, 0, $imageY - 1, $font_size + 7, $border_color);
     //逐行炫耀背景,全屏用1或0
     for ($i = 2; $i < $font_size + 6; $i++) {
         //获取随机淡色
         $line_color = imagecolorallocate($im, rand(180, 255), rand(180, 255), rand(180, 255));
         //画线
         imageline($im, 2, $i, $imageY - 3, $i, $line_color);
     }
     for ($i = 0; $i < $len; $i++) {
         //获取随机较深颜色
         $text_color = imagecolorallocate($im, rand($imageY, 180), rand($imageY, 180), rand($imageY, 180));
         //画文字
         imagechar($im, $font_size, $imstr[$i]["x"], $imstr[$i]["y"], $imstr[$i]["c"], $text_color);
     }
     header("Content-type: image/png");
     //显示图片
     imagepng($im);
     //销毁图片
     imagedestroy($im);
 }
Ejemplo n.º 30
0
function vvcode_render_code($code)
{
    if (!empty($code)) {
        $imwidth = 200;
        $imheight = 40;
        $font_size = $imheight * 0.75;
        $font_position = $imheight * 0.3;
        Header("Content-type: image/Jpeg");
        $im = @ImageCreate($imwidth, $imheight) or die("Cannot Initialize new GD image stream");
        $background_color = ImageColorAllocate($im, 255, 255, 255);
        $text_color = ImageColorAllocate($im, 64, 55, 53);
        $border_color = ImageColorAllocate($im, 178, 178, 178);
        $noise_color = ImageColorAllocate($im, 200, 207, 220);
        /* generate random dots in background */
        for ($n = 0; $n < $imwidth * $imheight / 3; $n++) {
            imagefilledellipse($im, mt_rand(0, $imwidth), mt_rand(0, $imheight), 1, 1, $noise_color);
        }
        /* generate random lines in background */
        for ($n = 0; $n < $imwidth * $imheight / 150; $n++) {
            imageline($im, mt_rand(0, $imwidth), mt_rand(0, $imheight), mt_rand(0, $imwidth), mt_rand(0, $imheight), $noise_color);
        }
        //strip any spaces that may have crept in
        //end-user wouldn't know to type the space! :)
        $code = str_replace(" ", "", $code);
        $x = 0;
        $stringlength = strlen($code);
        for ($i = 0; $i < $stringlength; $i++) {
            $x = $x + $font_size;
            $y = $font_position;
            $font = ImageLoadFont("includes/fonts/automatic.gdf");
            $single_char = substr($code, $i, 1);
            imagechar($im, $font, $x, $y, $single_char, $text_color);
        }
        imagerectangle($im, 0, 0, $imwidth - 1, $imheight - 1, $border_color);
        ImageJpeg($im);
        ImageDestroy;
    }
}