diff --git a/README.md b/README.md index 4a6c25c..973f3b2 100644 --- a/README.md +++ b/README.md @@ -30,4 +30,4 @@ $this->validate($data,[ if(!captcha_check($captcha)){ //验证失败 }; -~~~ \ No newline at end of file +~~~ diff --git a/src/Captcha.php b/src/Captcha.php index 29f9dad..c9ae867 100644 --- a/src/Captcha.php +++ b/src/Captcha.php @@ -46,6 +46,8 @@ class Captcha // 背景颜色 'reset' => true, // 验证成功后是否重置 + 'base64' => false, + // 返回base64编码图片 ]; private $im = null; // 验证码图片实例 @@ -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'); + } } /**