コード例 #1
0
ファイル: CaptchaTool.class.php プロジェクト: dower-d/shop
 /**
  * 以指定图片为模板,生成随机的验证码,存放在session库中
  */
 public static function generate()
 {
     header('Content-Type:image/jpeg');
     //加载画布
     $captcha = TOOL_PATH . '/captcha/' . mt_rand(1, 8) . '.jpg';
     $image = imagecreatefromjpeg($captcha);
     //在画布设置颜色
     $white = imagecolorallocate($image, 255, 255, 255);
     $black = imagecolorallocate($image, 0, 0, 0);
     $color = mt_rand(1, 2) == 1 ? $white : $black;
     //待画的字符串
     $code = self::getRandStr();
     //保存在session库中
     SessionTool::getInstance();
     $_SESSION['code'] = $code;
     //在画布中画矩形
     imagerectangle($image, 0, 0, 199, 79, $white);
     //在画布中写字
     imagestring($image, 5, 52, 3, $code, $color);
     //设置header头为图片
     //输出图片
     imagejpeg($image);
     //销毁图片
     imagedestroy($image);
 }
コード例 #2
0
ファイル: LineChart.php プロジェクト: msd1310/ci_bootstrap
 /**
  * Print the axis.
  */
 protected function printAxis()
 {
     $minValue = $this->axis->getLowerBoundary();
     $maxValue = $this->axis->getUpperBoundary();
     $stepValue = $this->axis->getTics();
     // Get graphical obects
     $img = $this->plot->getImg();
     $palette = $this->plot->getPalette();
     $text = $this->plot->getText();
     // Get the graph area
     $graphArea = $this->plot->getGraphArea();
     // Vertical axis
     for ($value = $minValue; $value <= $maxValue; $value += $stepValue) {
         $y = $graphArea->y2 - ($value - $minValue) * ($graphArea->y2 - $graphArea->y1) / $this->axis->displayDelta;
         imagerectangle($img, $graphArea->x1 - 3, $y, $graphArea->x1 - 2, $y + 1, $palette->axisColor[0]->getColor($img));
         imagerectangle($img, $graphArea->x1 - 1, $y, $graphArea->x1, $y + 1, $palette->axisColor[1]->getColor($img));
         $text->printText($img, $graphArea->x1 - 5, $y, $this->plot->getTextColor(), $value, $text->fontCondensed, $text->HORIZONTAL_RIGHT_ALIGN | $text->VERTICAL_CENTER_ALIGN);
     }
     // Get first serie of a list
     $pointList = $this->getFirstSerieOfList();
     // Horizontal Axis
     $pointCount = count($pointList);
     reset($pointList);
     $columnWidth = ($graphArea->x2 - $graphArea->x1) / ($pointCount - 1);
     for ($i = 0; $i < $pointCount; $i++) {
         $x = $graphArea->x1 + $i * $columnWidth;
         imagerectangle($img, $x - 1, $graphArea->y2 + 2, $x, $graphArea->y2 + 3, $palette->axisColor[0]->getColor($img));
         imagerectangle($img, $x - 1, $graphArea->y2, $x, $graphArea->y2 + 1, $palette->axisColor[1]->getColor($img));
         $point = current($pointList);
         next($pointList);
         $label = $point->getX();
         $text->printDiagonal($img, $x - 5, $graphArea->y2 + 10, $this->plot->getTextColor(), $label);
     }
 }
コード例 #3
0
ファイル: code_char.php プロジェクト: hanpc/chushen
function getCode($num, $w, $h)
{
    // 去掉了 0 1 O l 等
    $str = "23456789abcdefghijkmnpqrstuvwxyz";
    $code = '';
    for ($i = 0; $i < $num; $i++) {
        $code .= $str[mt_rand(0, strlen($str) - 1)];
    }
    //将生成的验证码写入session,备验证页面使用
    $_SESSION["my_checkcode"] = $code;
    //创建图片,定义颜色值
    Header("Content-type: image/PNG");
    $im = imagecreate($w, $h);
    $black = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
    $gray = imagecolorallocate($im, 118, 151, 199);
    $bgcolor = imagecolorallocate($im, 235, 236, 237);
    //画背景
    imagefilledrectangle($im, 0, 0, $w, $h, $bgcolor);
    //画边框
    imagerectangle($im, 0, 0, $w - 1, $h - 1, $gray);
    //imagefill($im, 0, 0, $bgcolor);
    //在画布上随机生成大量点,起干扰作用;
    for ($i = 0; $i < 80; $i++) {
        imagesetpixel($im, rand(0, $w), rand(0, $h), $black);
    }
    //将字符随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
    $strx = rand(5, 10);
    for ($i = 0; $i < $num; $i++) {
        $strpos = rand(1, 6);
        imagestring($im, 20, $strx, $strpos, substr($code, $i, 1), $black);
        $strx += $w / 5;
    }
    imagepng($im);
    imagedestroy($im);
}
コード例 #4
0
ファイル: bChart.php プロジェクト: abdeljawwad/sedr
 function drawGraphArea($R, $G, $B)
 {
     $color = imagecolorallocate($this->img, $R, $G, $B);
     $x1 = $this->init['x1'];
     $y1 = $this->init['y1'];
     $x2 = $this->init['x2'];
     $y2 = $this->init['y2'];
     imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $color);
     $color2 = imagecolorallocate($this->img, $R - 40, $G - 40, $B - 40);
     imagerectangle($this->img, $x1, $y1, $x2, $y2, $color2);
     if (!$this->init['bgStripe']) {
         return;
     }
     $color3 = imagecolorallocate($this->img, $R - 15, $G - 15, $B - 14);
     $imgH = $y2 - $y1 - 1;
     for ($i = $x1 - $imgH; $i <= $x2; $i = $i + 4) {
         $a1 = $i;
         $b1 = $y2;
         $a2 = $i + $imgH;
         $b2 = $y1;
         if ($a1 < $x1) {
             $a1 = $x1;
             $b1 = $y1 + $a2 - $x1 + 1;
         }
         if ($a2 >= $x2) {
             $b2 = $y1 + $a2 - $x2 + 1;
             $a2 = $x2 - 1;
         }
         imageline($this->img, $a1, $b1, $a2, $b2 + 1, $color3);
     }
 }
コード例 #5
0
ファイル: captcha.php プロジェクト: FantasticThought/tfsda
function imgcode($nums, $width, $high)
{
    //去除了數字0和1 字母小寫O和L,為了避免辨識不清楚
    //$str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMOPQRSTUBWXYZ";
    $str = "0123456789";
    $code = '';
    for ($i = 0; $i < $nums; $i++) {
        $code .= $str[mt_rand(0, strlen($str) - 1)];
    }
    $_SESSION['captcha'] = $code;
    //建立圖示,設置寬度及高度與顏色等等條件
    $image = imagecreate($width, $high);
    $black = imagecolorallocate($image, mt_rand(0, 200), mt_rand(0, 200), mt_rand(0, 200));
    $border_color = imagecolorallocate($image, 21, 106, 235);
    $background_color = imagecolorallocate($image, 235, 236, 237);
    //建立圖示背景
    imagefilledrectangle($image, 0, 0, $width, $high, $background_color);
    //建立圖示邊框
    imagerectangle($image, 0, 0, $width - 1, $high - 1, $border_color);
    //在圖示布上隨機產生大量躁點
    for ($i = 0; $i < 80; $i++) {
        imagesetpixel($image, rand(0, $width), rand(0, $high), $black);
    }
    $strx = rand(3, 8);
    for ($i = 0; $i < $nums; $i++) {
        $strpos = rand(1, 6);
        imagestring($image, 5, $strx, $strpos, substr($code, $i, 1), $black);
        $strx += rand(10, 30);
    }
    imagepng($image);
    imagedestroy($image);
}
コード例 #6
0
ファイル: verify.php プロジェクト: topstdio/xnova
function createAuthNumImg($randStr, $imgW = 100, $imgH = 40, $fontName)
{
    $image = imagecreate($imgW, $imgH);
    $color_white = imagecolorallocate($image, 255, 255, 255);
    $color_gray = imagecolorallocate($image, 228, 228, 228);
    $color_black = imagecolorallocate($image, 255, 102, 204);
    $color_radom = imagecolorallocate($image, rand(1, 200), rand(1, 200), rand(10, 250));
    for ($i = 0; $i < 2000; $i++) {
        $c = imagecolorallocate($image, rand(1, 200), rand(1, 200), rand(10, 250));
        imagesetpixel($image, mt_rand(0, $imgW), mt_rand(0, $imgH), $c);
        //Ìí¼ÓÔÓµã
    }
    imagerectangle($image, 0, 0, $imgW - 1, $imgH - 1, $color_gray);
    imagettftext($image, 50, mt_rand(-2, 2), rand(0, 20), 50, $color_radom, $fontName, $randStr);
    for ($i = 10; $i < $imgH; $i += 10) {
        imageline($image, 0, $i, $imgW, $i, $color_gray);
    }
    //»­ºáÏß
    for ($i = 10; $i < $imgW; $i += 10) {
        imageline($image, $i, 0, $i, $imgH, $color_gray);
    }
    //»­ÊúÏß
    imagepng($image);
    imagedestroy($image);
}
コード例 #7
0
ファイル: captcha.class.php プロジェクト: phphonor/companycms
 /**
  * +----------------------------------------------------------
  * 图片上传的处理函数
  * +----------------------------------------------------------
  */
 function create_captcha()
 {
     $word = $this->create_word();
     // 把验证码字符串写入session
     $_SESSION['captcha'] = md5($word . DOU_SHELL);
     // 绘制基本框架
     $im = imagecreatetruecolor($this->captcha_width, $this->captcha_height);
     $bg_color = imagecolorallocate($im, 235, 236, 237);
     imagefilledrectangle($im, 0, 0, $this->captcha_width, $this->captcha_height, $bg_color);
     $border_color = imagecolorallocate($im, 118, 151, 199);
     imagerectangle($im, 0, 0, $this->captcha_width - 1, $this->captcha_height - 1, $border_color);
     // 添加干扰
     for ($i = 0; $i < 5; $i++) {
         $rand_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagearc($im, mt_rand(-$this->captcha_width, $this->captcha_width), mt_rand(-$this->captcha_height, $this->captcha_height), mt_rand(30, $this->captcha_width * 2), mt_rand(20, $this->captcha_height * 2), mt_rand(0, 360), mt_rand(0, 360), $rand_color);
     }
     for ($i = 0; $i < 50; $i++) {
         $rand_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($im, mt_rand(0, $this->captcha_width), mt_rand(0, $this->captcha_height), $rand_color);
     }
     // 生成验证码图片
     $text_color = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
     imagestring($im, 6, 18, 5, $word, $text_color);
     // header
     header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");
     header("Content-type: image/png;charset=utf-8");
     /* 绘图结束 */
     imagepng($im);
     imagedestroy($im);
     return true;
 }
コード例 #8
0
ファイル: Primitive.php プロジェクト: Hassanj343/candidats
 /**
  * Draw a filled gray box with thick borders and darker corners.
  *
  * @param integer top left coordinate (x)
  * @param integer top left coordinate (y)
  * @param integer bottom right coordinate (x)
  * @param integer bottom right coordinate (y)
  * @param Color edge color
  * @param Color corner color
  */
 public function outlinedBox($x1, $y1, $x2, $y2, $color0, $color1) {
     imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $color0->getColor($this->img));
     imagerectangle($this->img, $x1, $y1, $x1 + 1, $y1 + 1, $color1->getColor($this->img));
     imagerectangle($this->img, $x2 - 1, $y1, $x2, $y1 + 1, $color1->getColor($this->img));
     imagerectangle($this->img, $x1, $y2 - 1, $x1 + 1, $y2, $color1->getColor($this->img));
     imagerectangle($this->img, $x2 - 1, $y2 - 1, $x2, $y2, $color1->getColor($this->img));
 }
コード例 #9
0
ファイル: image.class.php プロジェクト: 43431655/qizhongbao
 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');
 }
コード例 #10
0
ファイル: gd_rectangle.php プロジェクト: Sajaki/addons
/**
 * GD Rectangle Function
 *
 * @param class $siggen
 * @param array $data
 * 		int x
 * 		int y
 * 		int x2
 * 		int y2
 * 		bool filled
 * 		int radius
 * 		string color
 * 		int alpha
 *
 * @return bool
 */
function gd_rectangle($siggen, $data)
{
    // Get our color index
    $color = $this->set_color($data['color'], $data['alpha']);
    // Make sure radius is a positive number
    $data['radius'] = abs($data['radius']);
    // Only do this "massive" drawing if we have rounded corners
    if ($data['radius'] > 0) {
        if ($data['filled'] == 1) {
            imagefilledrectangle($siggen->im, $data['x'] + $data['radius'], $data['y'], $data['x2'] - $data['radius'], $data['y2'], $color);
            imagefilledrectangle($siggen->im, $data['x'], $data['y'] + $data['radius'], $data['x'] + $data['radius'] - 1, $data['y2'] - $data['radius'], $color);
            imagefilledrectangle($siggen->im, $data['x2'] - $data['radius'] + 1, $data['y'] + $data['radius'], $data['x2'], $data['y2'] - $data['radius'], $color);
            imagefilledarc($siggen->im, $data['x'] + $data['radius'], $data['y'] + $data['radius'], $data['radius'] * 2, $data['radius'] * 2, 180, 270, $color, IMG_ARC_PIE);
            imagefilledarc($siggen->im, $data['x2'] - $data['radius'], $data['y'] + $data['radius'], $data['radius'] * 2, $data['radius'] * 2, 270, 360, $color, IMG_ARC_PIE);
            imagefilledarc($siggen->im, $data['x'] + $data['radius'], $data['y2'] - $data['radius'], $data['radius'] * 2, $data['radius'] * 2, 90, 180, $color, IMG_ARC_PIE);
            imagefilledarc($siggen->im, $data['x2'] - $data['radius'], $data['y2'] - $data['radius'], $data['radius'] * 2, $data['radius'] * 2, 360, 90, $color, IMG_ARC_PIE);
        } else {
            imageline($siggen->im, $data['x'] + $data['radius'], $data['y'], $data['x2'] - $data['radius'], $data['y'], $color);
            imageline($siggen->im, $data['x'] + $data['radius'], $data['y2'], $data['x2'] - $data['radius'], $data['y2'], $color);
            imageline($siggen->im, $data['x'], $data['y'] + $data['radius'], $data['x'], $data['y2'] - $data['radius'], $color);
            imageline($siggen->im, $data['x2'], $data['y'] + $data['radius'], $data['x2'], $data['y2'] - $data['radius'], $color);
            imagearc($siggen->im, $data['x'] + $data['radius'], $data['y'] + $data['radius'], $data['radius'] * 2, $data['radius'] * 2, 180, 270, $color);
            imagearc($siggen->im, $data['x2'] - $data['radius'], $data['y'] + $data['radius'], $data['radius'] * 2, $data['radius'] * 2, 270, 360, $color);
            imagearc($siggen->im, $data['x'] + $data['radius'], $data['y2'] - $data['radius'], $data['radius'] * 2, $data['radius'] * 2, 90, 180, $color);
            imagearc($siggen->im, $data['x2'] - $data['radius'], $data['y2'] - $data['radius'], $data['radius'] * 2, $data['radius'] * 2, 360, 90, $color);
        }
    } else {
        if ($data['filled'] == 1) {
            imagefilledrectangle($siggen->im, $data['x'], $data['y'], $data['x2'], $data['y2'], $color);
        } else {
            imagerectangle($siggen->im, $data['x'], $data['y'], $data['x2'], $data['y2'], $color);
        }
    }
    return TRUE;
}
コード例 #11
0
ファイル: captcha.php プロジェクト: neilor/MuShopping-v3
function CreateImage()
{
    // cria o c�digo
    $md5Hash = md5(rand(0, 999));
    $securityCode = substr($md5Hash, 0, 6);
    // define a sess�o
    $_SESSION["SecurityCode"] = $securityCode;
    // dimens�es
    $width = 134;
    $height = 40;
    // cria imagem
    $image = @imagecreate($width, $height);
    // cores
    $white = imagecolorallocate($image, 0xff, 0xff, 0xff);
    $black = imagecolorallocate($image, 0x0, 0x0, 0x0);
    $grey = imagecolorallocate($image, 0x33, 0x33, 0x33);
    $blue = imagecolorallocate($image, 0x0, 0x0, 0xff);
    $red = imagecolorallocate($image, 0xff, 0x0, 0x0);
    $yellow = imagecolorallocate($image, 0xff, 0xff, 0x0);
    $arrayColors = array($grey, $black, $red, $blue);
    imagefill($image, 0, 0, $white);
    // escreve na imagem
    $arrayFonts = array("fonts/calibri.ttf", "fonts/berlin.ttf");
    for ($i = 0, $y = strlen($securityCode); $i < $y; $i++) {
        imagettftext($image, rand(13, 20), rand(-30, 30), 10 + 20 * $i, 25, $arrayColors[array_rand($arrayColors)], $arrayFonts[array_rand($arrayFonts)], $securityCode[$i]);
    }
    // faz uma borda
    imagerectangle($image, 0, 0, $width - 1, $height - 1, $grey);
    // fase final
    @header("Content-Type: image/jpeg");
    imagejpeg($image);
    imagedestroy($image);
}
コード例 #12
0
 protected function process(ViewBag $viewbag)
 {
     $movie = $this->movie;
     $list = $this->list;
     $im = imagecreate($this->W, $this->H);
     $background_color = imagecolorallocate($im, 0xc0, 0xc0, 0xc0);
     imagefilledrectangle($im, 0, 0, $this->W - 1, $this->H - 1, $background_color);
     $black = imagecolorallocate($im, 0, 0, 0);
     imagerectangle($im, 0, 0, $this->W - 1, $this->H - 1, $black);
     $red = imagecolorallocate($im, 0xc0, 0, 0);
     $max = $movie->getMaxSeek();
     $scale = DoubleVal($this->W) / DoubleVal($max);
     foreach ($list->getCutRegions() as $v) {
         $left = $v[0];
         $right = $v[1];
         if ($right == -1) {
             $right = $max;
         }
         $x1 = IntVal($left * $scale);
         $x2 = min($this->W - 1, IntVal($right * $scale));
         imagefilledrectangle($im, $x1, 1, $x2, $this->H - 2, $red);
     }
     header("Content-Type: image/png");
     header("Cache-Control: must-revalidate");
     imagepng($im);
     exit;
 }
コード例 #13
0
ファイル: Captcha.php プロジェクト: qdsay/cms
 /**
  * Create verify code
  */
 public function create()
 {
     //Image width(px)
     $this->width || ($this->width = $this->length * $this->fontsize * 1.5 + $this->fontsize * 1.5);
     //Image height(px)
     $this->height || ($this->height = $this->fontsize * 2);
     // Create $this->width x $this->height image
     $this->image = imagecreate($this->width, $this->height);
     //Set the background
     imagecolorallocate($this->image, $this->bg[0], $this->bg[1], $this->bg[2]);
     //Random font color of the verify code
     $this->color = imagecolorallocate($this->image, mt_rand(156, 256), mt_rand(156, 256), mt_rand(156, 256));
     //Set the border
     imagerectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $this->color);
     //Draw noise
     $this->writeNoise();
     //Drawn curve
     $this->writeCurve();
     //Drawn verify code
     $this->writeCode();
     //Save verify code
     $this->saveCode();
     //Output image
     imagepng($this->image);
     imagedestroy($this->image);
     $this->ci->output->set_content_type('png')->set_output($this->image);
 }
コード例 #14
0
 public function encodeImage(ImageCaptcha $ci)
 {
     $w = $ci->getCaptcha()->getWidth();
     $h = $ci->getCaptcha()->getHeight();
     $image = imagecreatetruecolor($w, $h);
     imagefilledrectangle($image, 0, 0, $w, $h, $this->toHex($ci->getBackgroundColor()));
     imagerectangle($image, 0, 0, $w - 1, $h - 1, $this->toHex($ci->getBorderColor()));
     // border
     $lines = $ci->getLines();
     foreach ($lines as $line) {
         $color = $this->toHex($line['color']);
         imageline($image, $line['x1'], $line['y1'], $line['x2'], $line['y2'], $color);
     }
     $fontSize = $ci->getCaptcha()->getFontSize();
     $box = imagettfbbox($fontSize, 0, $this->font, '0');
     $spacing = $ci->getCaptcha() instanceof MathCaptcha ? 0 : 5;
     $text = $ci->getText();
     $x = ($w - $fontSize * strlen(str_replace(' ', '', $text))) / 2;
     $y = $h / 2 - ($box[3] - $box[5]) / 2 + $fontSize;
     for ($i = 0; $i < strlen($text); $i++) {
         $angle = $ci->randAngle();
         $color = $this->toHex($ci->randColor());
         $box = imagettftext($image, $fontSize, $angle, $x, $y, $color, $this->font, $text[$i]);
         $x += $spacing + ($box[2] - $box[0]);
     }
     $temp = tempnam(sys_get_temp_dir(), 'captcha');
     imagepng($image, $temp);
     $data = fread(fopen($temp, 'r'), filesize($temp));
     $base64 = base64_encode($data);
     imagedestroy($image);
     unlink($temp);
     return 'data:image/png;base64,' . $base64;
 }
コード例 #15
0
ファイル: Image.class.php プロジェクト: fengxiangyun/diary
 /**
  * 
  * @brief 图片处理 验证码
  * @param unknown_type $length
  * @param unknown_type $mode
  * @param unknown_type $type
  * @param unknown_type $width
  * @param unknown_type $height
  * @param unknown_type $verifyName
  */
 public static function buildImageVerify($length = 4, $mode = 1, $type = 'png', $width = 48, $height = 22, $verifyName = 'verify')
 {
     $randval = self::randString($length, $mode);
     $_SESSION[$verifyName] = md5($randval);
     $width = $length * 10 + 10 > $width ? $length * 10 + 10 : $width;
     if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
         $im = imagecreatetruecolor($width, $height);
     } else {
         $im = imagecreate($width, $height);
     }
     $r = array(225, 255, 255, 223);
     $g = array(225, 236, 237, 255);
     $b = array(225, 236, 166, 125);
     $key = mt_rand(0, 3);
     $backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]);
     //背景色(随机)
     $borderColor = imagecolorallocate($im, 100, 100, 100);
     //边框色
     imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
     imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
     $stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
     // 干扰
     for ($i = 0; $i < 10; $i++) {
         imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(200, 300), mt_rand(35, 200), 55, 44, $stringColor);
     }
     for ($i = 0; $i < 25; $i++) {
         imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $stringColor);
     }
     for ($i = 0; $i < $length; $i++) {
         imagestring($im, 5, $i * 10 + 5, mt_rand(1, 8), $randval[$i], $stringColor);
     }
     Image::output($im, $type);
 }
コード例 #16
0
ファイル: bar.php プロジェクト: jekin000/hf_php
function draw_bar_graph($width, $height, $data, $max_value, $filename)
{
    /*1. Create the empty graph image*/
    $img = imagecreatetruecolor($width, $height);
    /*2. set a white background with black text and gray graphic*/
    $bg_color = imagecolorallocate($img, 255, 255, 255);
    //white
    $text_color = imagecolorallocate($img, 255, 255, 255);
    $bar_color = imagecolorallocate($img, 0, 0, 0);
    //black
    $border_color = imagecolorallocate($img, 192, 192, 192);
    //light gray
    /*3. fill the background */
    imagefilledrectangle($img, 0, 0, $width, $height, $bg_color);
    /*4. Draw the bars */
    $bar_width = $width / (count($data) * 2 + 1);
    for ($i = 0; $i < count($data); $i++) {
        imagefilledrectangle($img, $i * $bar_width * 2 + $bar_width, $height, $i * $bar_width * 2 + $bar_width * 2, $height - $height / $max_value * $data[$i][1], $bar_color);
        imagestringup($img, 5, $i * $bar_width * 2 + $bar_width, $height - 5, $data[$i][0], $text_color);
    }
    /*5. Draw a rectangle around the whole thing*/
    imagerectangle($img, 0, 0, $width - 1, $height - 1, $border_color);
    /*6. Draw the range up the left side of graph*/
    for ($i = 1; $i <= $max_value; $i++) {
        imagestring($img, 5, 0, $height - $i * ($height / $max_value), $i, $bar_color);
    }
    /*7. output image to a file.*/
    imagepng($img, $filename, 5);
    /*8. destroy image.*/
    imagedestroy($img);
}
コード例 #17
0
ファイル: verificationimg.php プロジェクト: ioanok/symfoxid
 /**
  * Generates image
  *
  * @param string $sMac verification code
  *
  * @return null
  */
 function generateVerificationImg($sMac)
 {
     $iWidth = 80;
     $iHeight = 18;
     $iFontSize = 14;
     if (function_exists('imagecreatetruecolor')) {
         // GD2
         $oImage = imagecreatetruecolor($iWidth, $iHeight);
     } elseif (function_exists('imagecreate')) {
         // GD1
         $oImage = imagecreate($iWidth, $iHeight);
     } else {
         // GD not found
         return;
     }
     $iTextX = ($iWidth - strlen($sMac) * imagefontwidth($iFontSize)) / 2;
     $iTextY = ($iHeight - imagefontheight($iFontSize)) / 2;
     $aColors = array();
     $aColors["text"] = imagecolorallocate($oImage, 0, 0, 0);
     $aColors["shadow1"] = imagecolorallocate($oImage, 200, 200, 200);
     $aColors["shadow2"] = imagecolorallocate($oImage, 100, 100, 100);
     $aColors["background"] = imagecolorallocate($oImage, 255, 255, 255);
     $aColors["border"] = imagecolorallocate($oImage, 0, 0, 0);
     imagefill($oImage, 0, 0, $aColors["background"]);
     imagerectangle($oImage, 0, 0, $iWidth - 1, $iHeight - 1, $aColors["border"]);
     imagestring($oImage, $iFontSize, $iTextX + 1, $iTextY + 0, $sMac, $aColors["shadow2"]);
     imagestring($oImage, $iFontSize, $iTextX + 0, $iTextY + 1, $sMac, $aColors["shadow1"]);
     imagestring($oImage, $iFontSize, $iTextX, $iTextY, $sMac, $aColors["text"]);
     header('Content-type: image/png');
     imagepng($oImage);
     imagedestroy($oImage);
 }
コード例 #18
0
ファイル: imageCode.php プロジェクト: 976112643/manor
function getCodeImg($num, $type = 2)
{
    $W = $num * 20;
    $H = 30;
    $code = getCode($num, $type);
    $img = imagecreatetruecolor($W, $H);
    $bg = imagecolorallocate($img, rand(155, 255), rand(155, 255), rand(155, 255));
    $borderColor = imagecolorallocate($img, 0, 0, 0);
    imagefill($img, 0, 0, $bg);
    imagerectangle($img, 0, 0, $W - 1, $H - 1, $borderColor);
    /*添加干扰点*/
    for ($i = 0; $i < 200; $i++) {
        imagesetpixel($img, rand(0, $W), rand(0, $H), imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255)));
    }
    /*添加干扰线*/
    for ($i = 0, $n = rand(2, 5); $i < $n; $i++) {
        imageline($img, rand(0, $W), rand(0, $H), rand(0, $W), rand(0, $H), imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255)));
    }
    /*绘制文字*/
    for ($i = 0; $i < $num; $i++) {
        $wordColor = imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255));
        imagettftext($img, 18, rand(-40, 40), 8 + 18 * $i, 24, $wordColor, "font\\msyh.ttc", $code[$i]);
    }
    return $img;
}
コード例 #19
0
ファイル: ValidateCode.php プロジェクト: yunkaiyueming/ci_cms
 private function getCreateImage()
 {
     $this->image = imagecreate($this->width, $this->height);
     $back = imagecolorallocate($this->image, 255, 255, 255);
     $border = imagecolorallocate($this->image, 0, 0, 0);
     imagerectangle($this->image, 0, 0, $this->width, $this->height, $border);
 }
コード例 #20
0
ファイル: DrawLine.php プロジェクト: BGCX262/zym-svn-to-git
 /**
  * Draw a line on the image, returns the GD-handle
  *
  * @param  GD image resource    $handle Image to work on
  * @param  Zend_Image_Action_DrawLine   $lineObject The object containing all settings needed for drawing a line.
  * @return void
  */
 public function perform(Zend_Image_Adapter_Gd $adapter, Zend_Image_Action_DrawLine $lineObject)
 {
     $handle = $adapter->getHandle();
     $strokeColor = $lineObject->getStrokeColor();
     $color = $strokeColor->getRgb();
     $colorAlphaAlloc = imagecolorallocatealpha($handle, $color['red'], $color['green'], $color['blue'], $lineObject->getStrokeAlpha());
     if ($lineObject->getStrokeWidth() == 1) {
         // Simple line
         imageline($handle, $lineObject->getPointStart()->getX(), $lineObject->getPointStart()->getY(), $lineObject->getPointEnd()->getX(), $lineObject->getPointEnd()->getY(), $colorAlphaAlloc);
     } elseif ($lineObject->getPointStart()->getX() == $lineObject->getPointEnd()->getX() || $lineObject->getPointStart()->getY() == $lineObject->getPointEnd()->getY()) {
         // Simple thick line
         $x1 = round(min($lineObject->getPointStart()->getX(), $lineObject->getPointEnd()->getX()) - ($lineObject->getStrokeWidth() / 2 - 0.5));
         $y1 = round(min($lineObject->getPointStart()->getY(), $lineObject->getPointEnd()->getY()) - ($lineObject->getStrokeWidth() / 2 - 0.5));
         $x2 = round(max($lineObject->getPointStart()->getX(), $lineObject->getPointEnd()->getX()) + ($lineObject->getStrokeWidth() / 2 - 0.5));
         $y2 = round(max($lineObject->getPointStart()->getY(), $lineObject->getPointEnd()->getY()) + ($lineObject->getStrokeWidth() / 2 - 0.5));
         if ($lineObject->isFilled()) {
             imagefilledrectangle($handle, $x1, $y1, $x2, $y2, $colorAlphaAlloc);
         } else {
             imagerectangle($handle, $x1, $y1, $x2, $y2, $colorAlphaAlloc);
         }
     } else {
         // Not horizontal nor vertical thick line
         $polygonObject = new Zend_Image_Action_DrawPolygon();
         $slope = ($lineObject->getPointEnd()->getY() - $lineObject->getPointStart()->getY()) / ($lineObject->getPointEnd()->getX() - $lineObject->getPointStart()->getX());
         // y = ax + b
         $a = ($lineObject->getStrokeWidth() / 2 - 0.5) / sqrt(1 + pow($slope, 2));
         $points = array(new Zend_Image_Point(round($lineObject->getPointStart()->getX() - (1 + $slope) * $a), round($lineObject->getPointStart()->getY() + (1 - $slope) * $a)), new Zend_Image_Point(round($lineObject->getPointStart()->getX() - (1 - $slope) * $a), round($lineObject->getPointStart()->getY() - (1 + $slope) * $a)), new Zend_Image_Point(round($lineObject->getPointEnd()->getX() + (1 + $slope) * $a), round($lineObject->getPointEnd()->getY() - (1 - $slope) * $a)), new Zend_Image_Point(round($lineObject->getPointEnd()->getX() + (1 - $slope) * $a), round($lineObject->getPointEnd()->getY() + (1 + $slope) * $a)));
         //Draw polygon
         $polygonObject = new Zend_Image_Action_DrawPolygon(array('points' => $points, 'strokeColor' => $strokeColor));
         $handler = new Zend_Image_Adapter_Gd_Action_DrawPolygon();
         $handle = $handler->perform($adapter, $polygonObject);
     }
     return $handle;
 }
コード例 #21
0
ファイル: Primitive.php プロジェクト: npetrovski/php5-image
 public function generate()
 {
     foreach ($this->__shapes as $shape) {
         $type = array_shift($shape);
         $color = array_shift($shape);
         $color = $this->_owner->imagecolorallocate(!isset($color) || is_null($color) ? $this->__base_color : $color, $this->__base_alpha);
         switch ($type) {
             case self::LINE:
                 imageline($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
                 break;
             case self::RECTANGLE:
                 imagerectangle($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
                 break;
             case self::FILLED_RECTANGLE:
                 imagefilledrectangle($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
                 break;
             case self::ELLIPSE:
                 imageellipse($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
                 break;
             case self::FILLED_ELLIPSE:
                 imagefilledellipse($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
                 break;
             case self::SPIRAL:
                 $angle = $r = 0;
                 while ($r <= $shape[2]) {
                     imagearc($this->_owner->image, $shape[0], $shape[1], $r, $r, $angle - $shape[3], $angle, $color);
                     $angle += $shape[3];
                     $r++;
                 }
                 break;
         }
     }
     return true;
 }
コード例 #22
0
ファイル: code.php プロジェクト: vpsguan/guantest
function _code($_width = 75, $_height = 25, $num = 4)
{
    for ($i = 0; $i < $num; $i++) {
        $_nmsg .= dechex(mt_rand(0, 15));
    }
    //保存到session
    $_SESSION['code'] = $_nmsg;
    //
    //创建图像
    $_img = imagecreatetruecolor($_width, $_height);
    //白
    $_white = imagecolorallocate($_img, 255, 255, 255);
    imagefill($_img, 0, 0, $_white);
    $_black = imagecolorallocate($_img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
    //	花边狂
    imagerectangle($_img, 0, 0, $_width - 1, $_height - 1, $_black);
    for ($i = 0; $i < 3; $i++) {
        $_rnd_color = imagecolorallocate($_img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
        imageline($_img, mt_rand(0, $_width), mt_rand(0, $_height), mt_rand(0, $_width), mt_rand(0, $_height), $_rnd_color);
    }
    //随即大雪花
    for ($i = 0; $i < 10; $i++) {
        imagestring($_img, 1, mt_rand(1, $_width), mt_rand(1, $_height), "*", imagecolorallocate($_img, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)));
    }
    //输出验证码
    for ($i = 0; $i < strlen($_SESSION['code']); $i++) {
        $_rnd_color = imagecolorallocate($_img, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200));
        imagestring($_img, 5, $i * $_width / $num + mt_rand(1, 10), mt_rand(1, $_height / 2), $_SESSION['code'][$i], $_rnd_color);
    }
    //输出图像
    header('Content-Type:image/png');
    imagepng($_img);
    //销毁
    imagedestroy($_img);
}
コード例 #23
0
ファイル: SC_Graph_Bar.php プロジェクト: casan/eccube-2_13
 /**
  * @param integer $line_no
  */
 public function drawBar($line_no)
 {
     $arrPointList = $this->arrPointList[$line_no];
     // データ数を数える
     $count = count($arrPointList);
     // 半目盛りの幅を求める
     $half_scale = intval($this->area_width / ($count + 1) / 2);
     // 目盛りの幅を求める
     $scale_width = intval($this->area_width / ($count + 1));
     // 棒グラフのサイズを求める
     $bar_width = intval(($scale_width - BAR_PAD * 2) / $this->line_max);
     // 色数の取得
     $c_max = count($this->arrColor);
     for ($i = 0; $i < $count; $i++) {
         $left = $arrPointList[$i][0] - $half_scale + BAR_PAD + $bar_width * $line_no;
         $top = $arrPointList[$i][1];
         $right = $left + $bar_width;
         $bottom = $this->top + $this->area_height;
         // 影の描画
         if ($this->shade_on) {
             imagefilledrectangle($this->image, $left + 2, $top + 2, $right + 2, $bottom, $this->shade_color);
         }
         //imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[($i % $c_max)]);
         imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[$line_no]);
         imagerectangle($this->image, $left, $top, $right, $bottom, $this->flame_color);
     }
 }
コード例 #24
0
ファイル: CheckCode.php プロジェクト: dalinhuang/andyou
 /**
  * 获得简单的验证码图片
  * @param array $paramArr 
  */
 public static function getCodeSimpleImage($paramArr)
 {
     $options = array('width' => 80, 'height' => 20, 'numCnt' => 4, 'inCode' => 'ABCD');
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     $text = self::getAuthCode($inCode);
     $font = APP_HTML_DIR . '/include/fonts/' . rand(1, 6) . '.ttf';
     $size = 14;
     $image = imagecreate($width, $height);
     $whiteColor = imagecolorallocate($image, 255, 255, 255);
     $blackColor = imagecolorallocate($image, 0, 0, 0);
     $count = $width * $height / 8;
     for ($i = 0; $i < $count; $i++) {
         $randomColor = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($image, mt_rand(0, $width), mt_rand(0, $height), $randomColor);
     }
     $fontSize = imagettfbbox($size, 0, $font, $text);
     $centerX = abs($fontSize[2] - $fontSize[0]);
     $centerY = abs($fontSize[5] - $fontSize[3]);
     $x = ($width - $centerX) / 2;
     $y = ($height - $centerY) / 2 + $centerY;
     imagettftext($image, $size, mt_rand(-2, +2), $x, $y - 2, $blackColor, $font, $text);
     imagerectangle($image, 0, 0, $width - 1, $height - 1, $blackColor);
     header("Content-type:image/png");
     imagepng($image);
     imagedestroy($image);
 }
コード例 #25
0
ファイル: LineChart.php プロジェクト: horrabin/opendb
 /**
  * Print the axis
  *
  * @access	private
  */
 function printAxis()
 {
     // Check if some points were defined
     if ($this->sampleCount < 2) {
         return;
     }
     $minValue = $this->axis->getLowerBoundary();
     $maxValue = $this->axis->getUpperBoundary();
     $stepValue = $this->axis->getTics();
     // Line axis
     for ($value = $minValue; $value <= $maxValue; $value += $stepValue) {
         $y = $this->graphBRY - ($value - $minValue) * ($this->graphBRY - $this->graphTLY) / $this->axis->displayDelta;
         imagerectangle($this->img, $this->graphTLX - 3, $y, $this->graphTLX - 2, $y + 1, $this->axisColor1->getColor($this->img));
         imagerectangle($this->img, $this->graphTLX - 1, $y, $this->graphTLX, $y + 1, $this->axisColor2->getColor($this->img));
         $this->text->printText($this->img, $this->graphTLX - 5, $y, $this->textColor, $value, $this->text->fontCondensed, $this->text->HORIZONTAL_RIGHT_ALIGN | $this->text->VERTICAL_CENTER_ALIGN);
     }
     // Horizontal Axis
     $columnWidth = ($this->graphBRX - $this->graphTLX) / ($this->sampleCount - 1);
     reset($this->point);
     for ($i = 0; $i < $this->sampleCount; $i++) {
         $x = $this->graphTLX + $i * $columnWidth;
         imagerectangle($this->img, $x - 1, $this->graphBRY + 2, $x, $this->graphBRY + 3, $this->axisColor1->getColor($this->img));
         imagerectangle($this->img, $x - 1, $this->graphBRY, $x, $this->graphBRY + 1, $this->axisColor2->getColor($this->img));
         $point = current($this->point);
         next($this->point);
         $text = $point->getX();
         $this->text->printDiagonal($this->img, $x - 5, $this->graphBRY + 10, $this->textColor, $text);
     }
 }
コード例 #26
0
ファイル: lib_code.php プロジェクト: Neo-Luo/amc
 public function image()
 {
     $code = '';
     for ($i = 0; $i < $this->how; $i++) {
         $code .= chr(mt_rand(65, 90));
     }
     $code = strtolower($code);
     $this->ci->session->set_userdata(array($this->name => $code));
     $len = strlen($code);
     $im = imagecreate($this->w, $this->h);
     imagecolorallocate($im, 255, 255, 255);
     $lineColor1 = imagecolorallocate($im, 240, 220, 180);
     $lineColor2 = imagecolorallocate($im, 250, 250, 170);
     for ($j = 3; $j <= $this->h; $j = $j + 3) {
         imageline($im, 2, $j, $this->w, $j, $lineColor1);
     }
     for ($j = 2; $j < $this->w; $j = $j + mt_rand(3, 6)) {
         imageline($im, $j, 2, $j - 6, 18, $lineColor2);
     }
     $bordercolor = imagecolorallocate($im, 0x99, 0x99, 0x99);
     imagerectangle($im, 0, 0, $this->w - 1, $this->h - 1, $bordercolor);
     $fontColor = imagecolorallocate($im, 48, 61, 50);
     for ($i = 0; $i < $len; $i++) {
         $bc = mt_rand(0, 3);
         $code[$i] = strtolower($code[$i]);
         imagestring($im, $this->size, $i * 11 + $this->w / 4 - $this->w / 10, mt_rand($this->h / 2 - 10, $this->h / 2 - 5), $code[$i], $fontColor);
     }
     header("Cache-Control:max-age=1,s-maxage=1,no-cache, must-revalidate");
     header("Content-type:image/png;");
     imagepng($im);
     imagedestroy($im);
     exit;
 }
コード例 #27
0
 public static function create()
 {
     $image = imagecreatetruecolor(100, 40) or die('cannot create canvas.<br>');
     $red = imagecolorallocate($image, 255, 0, 0);
     $green = imagecolorallocate($image, 0, 255, 0);
     $blue = imagecolorallocate($image, 0, 0, 255);
     $white = imagecolorallocate($image, 255, 255, 255);
     $black = imagecolorallocate($image, 0, 0, 0);
     imagefill($image, 0, 0, $white);
     imagerectangle($image, 1, 1, 99, 39, $black);
     $color = [$red, $green, $blue];
     for ($i = 1; $i <= 100; $i++) {
         imagesetpixel($image, mt_rand(2, 98), mt_rand(2, 38), $color[mt_rand(0, 2)]);
     }
     $source = "abcdefghigklmnopqrstuvwxyz0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ";
     $first = $source[mt_rand(0, 61)];
     $second = $source[mt_rand(0, 61)];
     $third = $source[mt_rand(0, 61)];
     $fourth = $source[mt_rand(0, 61)];
     $_SESSION['captcha'] = $first . $second . $third . $fourth;
     $font = dirname(dirname(__DIR__)) . '/../public/assets/fonts/SpicyRice.ttf';
     imagettftext($image, 20, mt_rand(-20, 20), 10, 30, $blue, $font, $first);
     imagettftext($image, 20, mt_rand(-20, 20), 30, 30, $blue, $font, $second);
     imagettftext($image, 20, mt_rand(-20, 20), 50, 30, $blue, $font, $third);
     imagettftext($image, 20, mt_rand(-20, 20), 70, 30, $blue, $font, $fourth);
     return imagejpeg($image);
 }
コード例 #28
0
ファイル: mask.php プロジェクト: digitaldevelopers/alegrocart
 function create_image($char_value)
 {
     //create canvas
     $img = imagecreatetruecolor($this->size_x + 10, $this->size_y);
     //set colors
     $background = imagecolorallocate($img, 255, 255, 255);
     $border = imagecolorallocate($img, 128, 128, 128);
     $colors[] = imagecolorallocate($img, 128, 64, 192);
     $colors[] = imagecolorallocate($img, 192, 64, 128);
     $colors[] = imagecolorallocate($img, 108, 192, 64);
     // fill background
     imagefilledrectangle($img, 1, 1, $this->size_x + 10 - 2, $this->size_y - 2, $background);
     imagerectangle($img, 0, 0, $this->size_x + 10 - 1, $this->size_y - 1, $border);
     //draw text
     for ($i = 0; $i < count($char_value); $i++) {
         $color = $colors[$i % count($colors)];
         imagettftext($img, 28 + rand(0, 8), -20 + rand(0, 40), ($i + 0.3) * $this->space_per_char, 45 + rand(0, 10), $color, DIR_FONTS . 'luggerbu.ttf', $char_value[$i]);
     }
     for ($i = 0; $i < 1000; $i++) {
         $x1 = rand(5, $this->size_x + 10 - 5);
         $y1 = rand(5, $this->size_y - 5);
         $x2 = $x1 - 4 + rand(0, 8);
         $y2 = $y1 - 4 + rand(0, 8);
         imageline($img, $x1, $y1, $x2, $y2, $colors[rand(0, count($colors) - 1)]);
     }
     return $img;
 }
コード例 #29
0
ファイル: mymismatch.php プロジェクト: khk0613/YHK
function draw_bar_graph($width, $height, $data, $max_value, $filename)
{
    // Create the empty graph image
    $img = imagecreatetruecolor($width, $height);
    // Set a white background with black text and gray graphics
    $bg_color = imagecolorallocate($img, 255, 255, 255);
    // white
    $text_color = imagecolorallocate($img, 255, 255, 255);
    // white
    $bar_color = imagecolorallocate($img, 0, 0, 0);
    // black
    $border_color = imagecolorallocate($img, 192, 192, 192);
    // light gray
    // Fill the background
    imagefilledrectangle($img, 0, 0, $width, $height, $bg_color);
    // Draw the bars
    $bar_width = $width / (count($data) * 2 + 1);
    for ($i = 0; $i < count($data); $i++) {
        imagefilledrectangle($img, $i * $bar_width * 2 + $bar_width, $height, $i * $bar_width * 2 + $bar_width * 2, $height - $height / $max_value * $data[$i][1], $bar_color);
        imagestringup($img, 5, $i * $bar_width * 2 + $bar_width, $height - 5, $data[$i][0], $text_color);
    }
    // Draw a rectangle around the whole thing
    imagerectangle($img, 0, 0, $width - 1, $height - 1, $border_color);
    // Draw the range up the left side of the graph
    for ($i = 1; $i <= $max_value; $i++) {
        imagestring($img, 5, 0, $height - $i * ($height / $max_value), $i, $bar_color);
    }
    // Write the graph image to a file
    imagepng($img, $filename, 5);
    imagedestroy($img);
}
コード例 #30
0
ファイル: Images.php プロジェクト: kevinwan/xf
 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);
 }