当前位置: 首页>>代码示例>>PHP>>正文


PHP ImageColorallocate函数代码示例

本文整理汇总了PHP中ImageColorallocate函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageColorallocate函数的具体用法?PHP ImageColorallocate怎么用?PHP ImageColorallocate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ImageColorallocate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create_captcha

function create_captcha($width = 60, $height = 32)
{
    session_start();
    //生成验证码图片
    Header("Content-type: image/PNG");
    $im = imagecreate($width, $height);
    // width and height of image
    $back = ImageColorAllocate($im, 245, 245, 245);
    // specify background color
    imagefill($im, 0, 0, $back);
    // fill the background color into image
    $vcodes = "";
    srand((double) microtime() * 1000000);
    //生成4位数字
    for ($i = 0; $i < 4; $i++) {
        $font = ImageColorAllocate($im, rand(100, 255), rand(0, 100), rand(100, 255));
        // 生成随机颜色
        $authnum = rand(1, 9);
        $vcodes .= $authnum;
        imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font);
    }
    for ($i = 0; $i < 100; $i++) {
        // interuppting
        $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
        imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
        // 画像素点函数
    }
    ImagePNG($im);
    ImageDestroy($im);
    $_SESSION['captcha'] = $vcodes;
}
开发者ID:NingerJohn,项目名称:vfinder,代码行数:31,代码来源:code.php

示例2: create_captcha

function create_captcha()
{
    session_start();
    //生成验证码图片
    Header("Content-type: image/PNG");
    $im = imagecreate(44, 18);
    // 画一张指定宽高的图片
    $back = ImageColorAllocate($im, 245, 245, 245);
    // 定义背景颜色
    imagefill($im, 0, 0, $back);
    //把背景颜色填充到刚刚画出来的图片中
    $vcodes = "";
    srand((double) microtime() * 1000000);
    //生成4位数字
    for ($i = 0; $i < 4; $i++) {
        $font = ImageColorAllocate($im, rand(100, 255), rand(0, 100), rand(100, 255));
        // 生成随机颜色
        $authnum = rand(1, 9);
        $vcodes .= $authnum;
        imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font);
    }
    $_SESSION['VCODE'] = $vcodes;
    for ($i = 0; $i < 100; $i++) {
        $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
        imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
        // 画像素点函数
    }
    ImagePNG($im);
    ImageDestroy($im);
}
开发者ID:NingerJohn,项目名称:vfinder,代码行数:30,代码来源:captcha_helper.php

示例3: getAuthImage

 function getAuthImage($text)
 {
     $this->setpin($text);
     $im_x = 160;
     $im_y = 40;
     $im = imagecreatetruecolor($im_x, $im_y);
     $text_c = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
     $tmpC0 = mt_rand(100, 255);
     $tmpC1 = mt_rand(100, 255);
     $tmpC2 = mt_rand(100, 255);
     $buttum_c = ImageColorAllocate($im, $tmpC0, $tmpC1, $tmpC2);
     imagefill($im, 16, 13, $buttum_c);
     $font = PATH_SYS_PUBLIC . 'font-awesome/fonts/verdana.ttf';
     for ($i = 0; $i < strlen($text); $i++) {
         $tmp = substr($text, $i, 1);
         $array = array(-1, 1);
         $p = array_rand($array);
         $an = $array[$p] * mt_rand(1, 10);
         //角度
         $size = 28;
         imagettftext($im, $size, $an, 15 + $i * $size, 35, $text_c, $font, $tmp);
     }
     $distortion_im = imagecreatetruecolor($im_x, $im_y);
     imagefill($distortion_im, 16, 13, $buttum_c);
     for ($i = 0; $i < $im_x; $i++) {
         for ($j = 0; $j < $im_y; $j++) {
             $rgb = imagecolorat($im, $i, $j);
             if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
                 imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 2 * M_PI - M_PI * 0.1) * 4), $j, $rgb);
             }
         }
     }
     //加入干扰象素;
     $count = 160;
     //干扰像素的数量
     for ($i = 0; $i < $count; $i++) {
         $randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
     }
     $rand = mt_rand(5, 30);
     $rand1 = mt_rand(15, 25);
     $rand2 = mt_rand(5, 10);
     for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
         for ($px = -80; $px <= 80; $px = $px + 0.1) {
             $x = $px / $rand1;
             if ($x != 0) {
                 $y = sin($x);
             }
             $py = $y * $rand2;
             imagesetpixel($distortion_im, $px + 80, $py + $yy, $text_c);
         }
     }
     //设置文件头;
     Header("Content-type: image/JPEG");
     //以PNG格式将图像输出到浏览器或文件;
     ImagePNG($distortion_im);
     //销毁一图像,释放与image关联的内存;
     ImageDestroy($distortion_im);
     ImageDestroy($im);
 }
开发者ID:nanfs,项目名称:lt,代码行数:60,代码来源:pin.class.php

示例4: rand_create

function rand_create()
{
    //通知浏览器将要输出PNG图片
    Header("Content-type: image/PNG");
    //准备好随机数发生器种子
    srand((double) microtime() * 1000000);
    //准备图片的相关参数
    $im = imagecreate(62, 20);
    $black = ImageColorAllocate($im, 0, 0, 0);
    //RGB黑色标识符
    $white = ImageColorAllocate($im, 255, 255, 255);
    //RGB白色标识符
    $gray = ImageColorAllocate($im, 200, 200, 200);
    //RGB灰色标识符
    //开始作图
    imagefill($im, 0, 0, $gray);
    while (($randval = rand() % 100000) < 10000) {
    }
    $_SESSION["login_check_num"] = $randval;
    //将四位整数验证码绘入图片
    imagestring($im, 5, 10, 3, $randval, $black);
    //加入干扰象素
    for ($i = 0; $i < 200; $i++) {
        $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
        imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
    }
    //输出验证图片
    ImagePNG($im);
    //销毁图像标识符
    ImageDestroy($im);
}
开发者ID:blackzw,项目名称:auth,代码行数:31,代码来源:VerifyCode.php

示例5: getAuthImage

 static function getAuthImage($text, $w = 200, $h = 40)
 {
     $im_x = $w;
     $im_y = $h;
     $im = imagecreatetruecolor($im_x, $im_y);
     $text_c = imagecolorallocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
     $button_c = imagecolorallocate($im, mt_rand(100, 255), mt_rand(100, 255), mt_rand(100, 255));
     imagefill($im, 16, 13, $button_c);
     $font = realpath(THINK_PATH . 'Common/Class/VerifyCode/') . '\\t1.ttf';
     $len = strlen($text);
     $mt_array = array(-1, 1);
     $size = 28;
     for ($i = 0; $i < $len; $i++) {
         $tmp = substr($text, $i, 1);
         $p = array_rand($mt_array);
         $an = $mt_array[$p] * mt_rand(1, 10);
         //角度
         imagettftext($im, $size, $an, 15 + $i * $size, 35, $text_c, $font, $tmp);
     }
     $distortion_im = imagecreatetruecolor($im_x, $im_y);
     imagefill($distortion_im, 16, 13, $button_c);
     for ($i = 0; $i < $im_x; $i++) {
         for ($j = 0; $j < $im_y; $j++) {
             $rgb = imagecolorat($im, $i, $j);
             if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
                 imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 2 * M_PI - M_PI * 0.1) * 4), $j, $rgb);
             }
         }
     }
     //加入干扰象素;
     $count = 160;
     //干扰像素的数量
     for ($i = 0; $i < $count; $i++) {
         $randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
     }
     $rand = mt_rand(5, 30);
     $rand1 = mt_rand(15, 25);
     $rand2 = mt_rand(5, 10);
     for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
         for ($px = -80; $px <= 80; $px = $px + 0.1) {
             $x = $px / $rand1;
             if ($x != 0) {
                 $y = sin($x);
             }
             $py = $y * $rand2;
             imagesetpixel($distortion_im, $px + 80, $py + $yy, $text_c);
         }
     }
     //设置文件头;
     Header("Content-type: image/JPEG");
     //以PNG格式将图像输出到浏览器或文件;
     ImagePNG($distortion_im);
     //销毁一图像,释放与image关联的内存;
     ImageDestroy($distortion_im);
     ImageDestroy($im);
 }
开发者ID:beelibrary820145,项目名称:tanxiongfeng,代码行数:57,代码来源:VerifyCode.class.php

示例6: getAuthImage

function getAuthImage($text, $im_x, $im_y, $move_x, $move_y, $font_size, $count)
{
    $im = imagecreatetruecolor($im_x, $im_y);
    $text_c = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
    $tmpC0 = mt_rand(100, 255);
    $tmpC1 = mt_rand(100, 255);
    $tmpC2 = mt_rand(100, 255);
    $buttum_c = ImageColorAllocate($im, $tmpC0, $tmpC1, $tmpC2);
    imagefill($im, 16, 13, $buttum_c);
    $font = '../font/Airbus.ttf';
    for ($i = 0; $i < strlen($text); $i++) {
        $tmp = substr($text, $i, 1);
        $array = array(-1, 1);
        $p = array_rand($array);
        $an = $array[$p] * mt_rand(1, 10);
        $size = $font_size;
        imagettftext($im, $size, $an, $i * $size + $move_x, $move_y, $text_c, $font, $tmp);
    }
    $distortion_im = imagecreatetruecolor($im_x, $im_y);
    imagefill($distortion_im, 16, 13, $buttum_c);
    for ($i = 0; $i < $im_x; $i++) {
        for ($j = 0; $j < $im_y; $j++) {
            $rgb = imagecolorat($im, $i, $j);
            if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
                imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 1 * M_PI - M_PI * 0.1) * 1), $j, $rgb);
            }
        }
    }
    for ($i = 0; $i < $count; $i++) {
        $randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
        imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
    }
    $rand = mt_rand(5, 30);
    $rand1 = mt_rand(1, 25);
    $rand2 = mt_rand(5, 10);
    for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
        for ($px = -80; $px <= 80; $px = $px + 0.1) {
            $x = $px / $rand1;
            if ($x != 0) {
                $y = sin($x);
            }
            $py = $y * $rand2;
            //imagesetpixel($distortion_im, $px+80, $py+$yy, $text_c);
        }
    }
    Header("Content-type: image/JPEG");
    ImagePNG($distortion_im);
    ImageDestroy($distortion_im);
    ImageDestroy($im);
}
开发者ID:ZeloTech,项目名称:dwct,代码行数:50,代码来源:check-code.php

示例7: captcha

 public function captcha()
 {
     $this->load->library('session');
     //生成验证码图片
     header("Content-type: image/png");
     //要显示的字符,可自己进行增删
     $str = "1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,m,n,p,q,r,s,t,y,z";
     $list = explode(",", $str);
     $cmax = count($list) - 1;
     $verifyCode = '';
     for ($i = 0; $i < 5; $i++) {
         $randnum = mt_rand(0, $cmax);
         //取出字符,组合成验证码字符
         $verifyCode .= $list[$randnum];
     }
     //避免程序读取session字符串破解,生成的验证码用MD5加密一下再放入session,提交的验证码md5以后和seesion存储的md5进行对比
     //直接md5还不行,别人反向md5后提交还是可以的,再加个特定混淆码再md5强度才比较高,总长度在14位以上
     //网上有反向md5的 Rainbow Table,64GB的量几分钟内就可以搞定14位以内大小写字母、数字、特殊字符的任意排列组合的MD5反向
     //但这种方法不能避免直接分析图片上的文字进行破解,生成gif动画比较难分析出来
     //加入前缀、后缀字符,prestr endstr 为自定义字符,将最终字符放入SESSION中
     //$_SESSION['randcode'] =  md5($this->prestr.$verifyCode.$this->endstr);
     $this->session->set_userdata('randcode', md5($this->session_prestr . $verifyCode . $this->session_endstr));
     //生成图片
     $im = imagecreate(65, 30);
     //此条及以下三条为设置的颜色
     $black = imagecolorallocate($im, 0, 0, 0);
     $white = imagecolorallocate($im, 255, 255, 255);
     $gray = imagecolorallocate($im, 200, 200, 200);
     $red = imagecolorallocate($im, 255, 0, 0);
     $blue = imagecolorallocate($im, 52, 126, 189);
     //给图片填充颜色
     imagefill($im, 0, 0, $white);
     //将验证码写入到图片中
     imagestring($im, 5, 10, 8, $verifyCode, $blue);
     //加入干扰象素
     for ($i = 0; $i < 50; $i++) {
         $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
         imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
     }
     imagepng($im);
     imagedestroy($im);
 }
开发者ID:tatfan,项目名称:fb_backend,代码行数:42,代码来源:index.php

示例8: display

 /**
  * 获取生成的Code
  * 
  * @return [type] [description]
  */
 public function display()
 {
     header("Content-type: image/PNG");
     $im = imagecreate(52, 20);
     $black = ImageColorallocate($im, 0, 0, 0);
     $white = ImageColorallocate($im, 230, 255, 255);
     $gray = ImageColorallocate($im, 200, 200, 255);
     $blue = ImageColorallocate($im, 40, 100, 225);
     imagefill($im, 0, 0, $white);
     $_SESSION['_authcode'] = $this->genCode();
     $authnum = $_SESSION['_authcode'];
     imagestring($im, 6, 8, 3, $authnum, $blue);
     for ($i = 0; $i < 200; $i++) {
         $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
         imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
     }
     ImagePNG($im);
     ImageDestroy($im);
     exit;
 }
开发者ID:lanma121,项目名称:superPrize,代码行数:25,代码来源:ValidImage.php

示例9: createCaptcha

 /**
  * @throws Exception
  * 生成验证码 , 存放到token相对应的session里面
  */
 public function createCaptcha()
 {
     $token = $_COOKIE["token"];
     if (empty($token)) {
         throw new Exception("无法生产验证码,请稍后在试");
     }
     $string = "abcdefghijklmnopqrstuvwxyz0123456789";
     $str = "";
     for ($i = 0; $i < 4; $i++) {
         $pos = rand(0, 35);
         $str .= $string[$pos];
     }
     $this->load->library('session');
     $flag = $this->session->set_userdata($token . "_captcha", $str);
     $img_handle = Imagecreate(80, 20);
     //图片大小80X20
     $back_color = ImageColorAllocate($img_handle, 255, 255, 255);
     //背景颜色(白色)
     $txt_color = ImageColorAllocate($img_handle, 0, 0, 0);
     //文本颜色(黑色)
     //加入干扰线
     for ($i = 0; $i < 3; $i++) {
         $line = ImageColorAllocate($img_handle, rand(0, 255), rand(0, 255), rand(0, 255));
         Imageline($img_handle, rand(0, 15), rand(0, 15), rand(100, 150), rand(10, 50), $line);
     }
     //加入干扰象素
     for ($i = 0; $i < 200; $i++) {
         $randcolor = ImageColorallocate($img_handle, rand(0, 255), rand(0, 255), rand(0, 255));
         Imagesetpixel($img_handle, rand() % 100, rand() % 50, $randcolor);
     }
     Imagefill($img_handle, 0, 0, $back_color);
     //填充图片背景色
     ImageString($img_handle, 28, 20, 0, $str, $txt_color);
     //水平填充一行字符串
     ob_clean();
     // ob_clean()清空输出缓存区
     header("Content-type: image/png");
     //生成验证码图片
     Imagepng($img_handle);
     //显示图片
 }
开发者ID:baiyk,项目名称:medicalProject,代码行数:45,代码来源:Verify_model.php

示例10: authCodeAction

 public function authCodeAction()
 {
     session_start();
     //生成验证码图片
     Header("Content-type: image/PNG ");
     srand((double) microtime() * 1000000);
     $authnum = rand(1000, 9999);
     $_SESSION['rand_code'] = $authnum;
     $im = imagecreate(62, 20);
     ImageColorAllocate($im, 0, 0, 0);
     $white = ImageColorAllocate($im, 255, 255, 255);
     //将五位整数验证码绘入图片
     imagestring($im, 5, 10, 3, $authnum, $white);
     //加入干扰象素
     for ($i = 0; $i < 200; $i++) {
         $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
         imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
     }
     ImagePNG($im);
     ImageDestroy($im);
 }
开发者ID:jiatower,项目名称:php,代码行数:21,代码来源:Public.php

示例11: handle_request

 public function handle_request()
 {
     $params = APF::get_instance()->get_request()->get_parameters();
     $cookiename = @$params['cn'];
     $x_size = $params['x'];
     $y_size = $params['y'];
     $num_size = $params['s'];
     //添加字符数量
     $font_num = isset($params['n']) ? $params['n'] : 4;
     $x1 = $params['x1'];
     $y1 = $params['y1'];
     $x2 = $params['x2'];
     $y2 = $params['y2'];
     $seccode = $this->random($font_num, 1);
     $md5seccode = Util_AuthorCrypt::encrypt($seccode, md5($_SERVER['HTTP_USER_AGENT']));
     //		if('askquestionreg'==$cookiename){
     //			$objMem=APF_Cache_Factory::get_instance()->get_memcache();
     //			$strGUID=APF::get_instance()->get_request()->get_cookie('aQQ_ajkguid');
     //			$objMem->set('askquestionreg_'.$strGUID,$md5seccode,0,90);
     //		}
     APF::get_instance()->get_response()->set_cookie($cookiename, $md5seccode, 30 * 60);
     header("Content-type: image/png");
     $im = imagecreatetruecolor($x_size, $y_size);
     $white = imagecolorallocate($im, 255, 255, 255);
     $grey = imagecolorallocate($im, 128, 128, 128);
     $black = imagecolorallocate($im, 0, 0, 0);
     imagefilledrectangle($im, 0, 0, $x_size, $y_size, $white);
     $font = APF::get_instance()->get_config("FontsUrl");
     //var_dump($font);exit;
     imagettftext($im, $num_size, 2, $x1, $y1, $grey, $font, $seccode);
     imagettftext($im, $num_size, 2, $x2, $y2, $black, $font, $seccode);
     for ($i = 0; $i < 600; $i++) {
         $randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
         imagesetpixel($im, rand() % $x_size, rand() % $y_size, $randcolor);
     }
     imagepng($im);
     imagedestroy($im);
     return false;
 }
开发者ID:emilymwang8,项目名称:ajk-broker,代码行数:39,代码来源:RegisterVerifyCode.php

示例12: handle_request

 public function handle_request()
 {
     $params = APF::get_instance()->get_request()->get_parameters();
     $x_size = $params['x'];
     $y_size = $params['y'];
     $num_size = $params['s'];
     //添加字符数量
     $font_num = isset($params['n']) ? $params['n'] : 4;
     $x1 = $params['x1'];
     $y1 = $params['y1'];
     $x2 = $params['x2'];
     $y2 = $params['y2'];
     $verifyCode = strtolower($this->random($font_num, 1));
     $keySuffix = md5($_SERVER['HTTP_USER_AGENT'] . $verifyCode);
     Bll_Security_Verify::saveVerifyCode($keySuffix, $verifyCode);
     $response = APF::get_instance()->get_response();
     $response->set_content_type('image/png');
     $response->set_cookie('sv', $keySuffix, 10 * 60, NULL, NULL, FALSE, TRUE);
     $response->set_cache_control('private');
     $response->set_header('Expires', 'Thu Jun 05 2014 11:41:06 GMT');
     $response->set_header('hash', $keySuffix);
     $response->set_header('Pragma', 'no-cache');
     $im = imagecreatetruecolor($x_size, $y_size);
     $white = imagecolorallocate($im, 255, 255, 255);
     $grey = imagecolorallocate($im, 128, 128, 128);
     $black = imagecolorallocate($im, 0, 0, 0);
     imagefilledrectangle($im, 0, 0, $x_size, $y_size, $white);
     $font = APF::get_instance()->get_config("FontsUrl");
     imagettftext($im, $num_size, 2, $x1, $y1, $grey, $font, $verifyCode);
     imagettftext($im, $num_size, 2, $x2, $y2, $black, $font, $verifyCode);
     for ($i = 0; $i < 600; $i++) {
         $randColor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
         imagesetpixel($im, rand() % $x_size, rand() % $y_size, $randColor);
     }
     imagepng($im);
     imagedestroy($im);
     return false;
 }
开发者ID:emilymwang8,项目名称:ajk-broker,代码行数:38,代码来源:VerifyCode.php

示例13: ob_start

<?php

ob_start();
if (!isset($_SESSION)) {
    session_start();
}
header('content-Type:image/gif');
echo mt_srand(time());
const width = 105;
const height = 33;
$length = strlen($_SESSION['ans_checknum']);
$img = imagecreate(width, height);
imagefill($img, 0, 0, ImageColorAllocate($img, 200, 200, 200));
for ($i = 0; $i < 250; $i++) {
    $randcolor = ImageColorallocate($img, rand(10, 250), rand(10, 250), rand(10, 250));
    imagesetpixel($img, rand() % width, rand() % height, $randcolor);
}
for ($i = 0; $i < $length; $i++) {
    $color = imagecolorallocate($img, abs(mt_rand() % 128), abs(mt_rand() % 128), abs(mt_rand() % 128));
    imagechar($img, height / 2, abs(mt_rand() % width / 8) + $i * width / 4, abs(mt_rand() % height / 2), $_SESSION['ans_checknum'][$i], $color);
}
imagegif($img);
imageDestroy($img);
ob_end_flush();
开发者ID:JackWangz,项目名称:E-Cushion,代码行数:24,代码来源:captcha_pic.php

示例14: verify

 public function verify()
 {
     //Image::buildImageVerify();
     $text = $this->make_rand(4);
     $_SESSION['verify'] = md5(strtolower($text));
     $im_x = 160;
     $im_y = 40;
     $im = imagecreatetruecolor($im_x, $im_y);
     $text_c = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
     $tmpC0 = mt_rand(100, 255);
     $tmpC1 = mt_rand(100, 255);
     $tmpC2 = mt_rand(100, 255);
     $buttum_c = ImageColorAllocate($im, $tmpC0, $tmpC1, $tmpC2);
     imagefill($im, 16, 13, $buttum_c);
     $font = $_SERVER['DOCUMENT_ROOT'] . '/tpl/' . MODULE_NAME . '/default/common/t1.ttf';
     for ($i = 0; $i < strlen($text); $i++) {
         $tmp = substr($text, $i, 1);
         $array = array(-1, 1);
         $p = array_rand($array);
         $an = $array[$p] * mt_rand(1, 10);
         //角度
         $size = 28;
         imagettftext($im, $size, $an, 15 + $i * $size, 35, $text_c, $font, $tmp);
     }
     $distortion_im = imagecreatetruecolor($im_x, $im_y);
     imagefill($distortion_im, 16, 13, $buttum_c);
     for ($i = 0; $i < $im_x; $i++) {
         for ($j = 0; $j < $im_y; $j++) {
             $rgb = imagecolorat($im, $i, $j);
             if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
                 imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 2 * M_PI - M_PI * 0.1) * 4), $j, $rgb);
             }
         }
     }
     //加入干扰象素;
     $count = 160;
     //干扰像素的数量
     for ($i = 0; $i < $count; $i++) {
         $randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
     }
     $rand = mt_rand(5, 30);
     $rand1 = mt_rand(15, 25);
     $rand2 = mt_rand(5, 10);
     for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
         for ($px = -80; $px <= 80; $px = $px + 0.1) {
             $x = $px / $rand1;
             if ($x != 0) {
                 $y = sin($x);
             }
             $py = $y * $rand2;
             imagesetpixel($distortion_im, $px + 80, $py + $yy, $text_c);
         }
     }
     //设置文件头;
     Header("Content-type: image/JPEG");
     //以PNG格式将图像输出到浏览器或文件;
     ImagePNG($distortion_im);
     //销毁一图像,释放与image关联的内存;
     ImageDestroy($distortion_im);
     ImageDestroy($im);
 }
开发者ID:zhaoshengloveqingqing,项目名称:Wechat,代码行数:62,代码来源:FxsAction.class.php

示例15: CodeAction

 public function CodeAction()
 {
     $im_x = 100;
     $im_y = 35;
     $im = imagecreatetruecolor($im_x, $im_y);
     $text_c = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
     $tmpC0 = mt_rand(100, 255);
     $tmpC1 = mt_rand(100, 255);
     $tmpC2 = mt_rand(100, 255);
     $buttum_c = ImageColorAllocate($im, $tmpC0, $tmpC1, $tmpC2);
     imagefill($im, 16, 1, $buttum_c);
     $font = 't1.ttf';
     $text = $this->make_rand(4);
     $session = $this->get('session');
     $session->set("code", strtolower($text));
     $this->get("logger")->err("========session code:" . $session->get("code"));
     $white = ImageColorAllocate($im, 0, 0, 0);
     $printtext = "";
     for ($index = 0; $index < 4; $index++) {
         $printtext .= $text[$index] . " ";
     }
     ImageString($im, 10, 10, 10, $printtext, $white);
     $distortion_im = imagecreatetruecolor($im_x, $im_y);
     imagefill($distortion_im, 16, 13, $buttum_c);
     for ($i = 0; $i < $im_x; $i++) {
         for ($j = 0; $j < $im_y; $j++) {
             $rgb = imagecolorat($im, $i, $j);
             if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
                 imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 2 * M_PI - M_PI * 0.1) * 4), $j, $rgb);
             }
         }
     }
     //加入干扰象素;
     $count = 150;
     //干扰像素的数量
     for ($i = 0; $i < $count; $i++) {
         $randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
     }
     $rand = mt_rand(5, 35);
     $rand1 = mt_rand(15, 25);
     $rand2 = mt_rand(5, 10);
     for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
         for ($px = -80; $px <= 80; $px = $px + 0.1) {
             $x = $px / $rand1;
             if ($x != 0) {
                 $y = sin($x);
             }
             $py = $y * $rand2;
             imagesetpixel($distortion_im, $px + 50, $py + $yy, $text_c);
         }
     }
     //设置文件头;
     Header("Content-type: image/png");
     ImagePNG($distortion_im);
     //销毁一图像,释放与image关联的内存;
     ImageDestroy($distortion_im);
     ImageDestroy($im);
     $response = new Response(json_encode(""));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
开发者ID:3116246,项目名称:haolinju,代码行数:62,代码来源:RegisterController.php


注:本文中的ImageColorallocate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。