Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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