Skip to content

Commit

Permalink
新增配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
JZaaa committed Feb 15, 2023
1 parent 924963d commit 614d6b5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/app.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
'length' => 4, // 验证码长度
'charset' => '2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ', // 验证码字符集
'applyPostEffects' => true, // 是否应用后期效果
'bgColor' => null, // 图片背景色
'lineColor' => null, // 干扰线颜色
'textColor' => null, // 文字颜色
]
]
];
34 changes: 32 additions & 2 deletions src/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ class Captcha
*/
protected $applyPostEffects = true;


/**
* 图片背景色
* @var null|string|array $bgColor
*/
protected $bgColor = null;

/**
* 文字颜色
* @var null|string|array $bgColor
*/
protected $lineColor = null;

/**
* 文字颜色
* @var null|string|array $bgColor
*/
protected $textColor = null;

/**
* Captcha constructor.
* @param array $config
Expand Down Expand Up @@ -112,10 +131,10 @@ protected function configure($config)
if (is_array($defaultConfig)) {
$config = array_merge($defaultConfig, $config);
}

$classVars = array_keys(get_class_vars(get_class($this)));

foreach ($config as $key => $item) {
if (isset($this->$key) && !in_array($key, $ignore)) {
if (in_array($key, $classVars) && !in_array($key, $ignore)) {
$this->$key = $item;
}
}
Expand Down Expand Up @@ -144,6 +163,17 @@ protected function generate()

$this->captchaBuilder->applyPostEffects = $this->applyPostEffects;

if ($this->bgColor) {
$this->captchaBuilder->bgColor = $this->bgColor;
}
if ($this->lineColor) {
$this->captchaBuilder->lineColor = $this->lineColor;
}
if ($this->textColor) {
$this->captchaBuilder->textColor = $this->textColor;
}


$this->captchaBuilder->build((int) $this->width,(int) $this->height);

$this->phrase = $this->captchaBuilder->phrase;
Expand Down

0 comments on commit 614d6b5

Please sign in to comment.