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返回给前台呢 #10

Open
TahmLi opened this issue Jul 16, 2021 · 1 comment
Open

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

TahmLi opened this issue Jul 16, 2021 · 1 comment

Comments

@TahmLi
Copy link

TahmLi commented Jul 16, 2021

No description provided.

@jaryf
Copy link

jaryf commented Sep 26, 2021

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

// 生成图片
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()),
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@TahmLi @jaryf and others