Yii 2.0 渲染随机颜色图片验证码(Captcha) 示例代码
//color lib
$colorLib[] = 0x2040A0;
$colorLib[] = 0x2F4F4F;
$colorLib[] = 0x483D8B;
$colorLib[] = 0xCDBE70;
$colorLib[] = 0xFFB90F;
$colorLib[] = 0xEE6363;
$colorLib[] = 0xFF1493;
//get rand color for front
$index = mt_rand(0, count($colorLib)-1);
$ca = new CaptchaAction('captcha', 'view');
$ca->fixedVerifyCode = '18+8'; //any kind code go here, will render in pic
$ca->foreColor = $colorLib[$index];
$ca->padding = 0;
$ca->width = 100;
// $ca->width = 300;
// $ca->height = 100;
echo $ca->run();
留言