Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加背景图片透明度设置 #62

Open
wants to merge 3 commits into
base: 3.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Captcha
protected $bg = [243, 251, 254];
//算术验证码
protected $math = false;
//从 0 到 127。0 表示完全不透明,127 表示完全透明。
protected $alpha = 0;

/**
* 架构方法 设置参数
Expand Down Expand Up @@ -180,7 +182,7 @@ public function create(string $config = null, bool $api = false): Response
// 建立一幅 $this->imageW x $this->imageH 的图像
$this->im = imagecreate((int) $this->imageW, (int) $this->imageH);
// 设置背景
imagecolorallocate($this->im, $this->bg[0], $this->bg[1], $this->bg[2]);
imagecolorallocatealpha($this->im, $this->bg[0], $this->bg[1], $this->bg[2], $this->alpha);

// 验证码字体随机颜色
$this->color = imagecolorallocate($this->im, mt_rand(1, 150), mt_rand(1, 150), mt_rand(1, 150));
Expand Down