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

增加base64编码支持 #33

Open
wants to merge 6 commits into
base: 2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ $this->validate($data,[
if(!captcha_check($captcha)){
//验证失败
};
~~~
~~~
9 changes: 8 additions & 1 deletion src/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class Captcha
// 背景颜色
'reset' => true,
// 验证成功后是否重置
'base64' => false,
// 返回base64编码图片
];

private $im = null; // 验证码图片实例
Expand Down Expand Up @@ -206,7 +208,12 @@ public function entry($id = '')
$content = ob_get_clean();
imagedestroy($this->im);

return response($content, 200, ['Content-Length' => strlen($content)])->contentType('image/png');
if ($this->base64) {
$content = 'data:image/png;base64,'.base64_encode($content);
return response($content, 200, ['Content-Length' => strlen($content)])->contentType('text/plain');
} else {
return response($content, 200, ['Content-Length' => strlen($content)])->contentType('image/png');
}
}

/**
Expand Down