captcha icon indicating copy to clipboard operation
captcha copied to clipboard

图片怎么返回成base64返回给前台呢

Open TahmLi opened this issue 3 years ago • 1 comments

TahmLi avatar Jul 16 '21 16:07 TahmLi

刚好我也有这个需求,我研究了一下,解决了,给你贴上解决方法

// 生成图片
img, imageText := mCaptcha.Create(4, captcha.NUM)
emptyBuff := bytes.NewBuffer(nil)
_ = png.Encode(emptyBuff, img)
response.WinJson(r, "成功", &g.Map{
  "id":   imageCodeId,
  "b64s": "data:image/png;base64," + base64.StdEncoding.EncodeToString(emptyBuff.Bytes()),
})

jaryf avatar Sep 26 '21 02:09 jaryf