This commit is contained in:
laodaming 2023-06-13 19:39:24 +08:00
parent f1d20d061c
commit 50bca808f1

View File

@ -31,7 +31,10 @@ func CreateQrCodeBs64WithLogo(content, outPath string, logoPath string, size, x,
if x != 0 || y != 0 { if x != 0 || y != 0 {
draw.Draw(outImg, outImg.Bounds().Add(image.Pt(x, y)), qrcodeImg, outImg.Bounds().Min, draw.Src) draw.Draw(outImg, outImg.Bounds().Add(image.Pt(x, y)), qrcodeImg, outImg.Bounds().Min, draw.Src)
} }
_ = png.Encode(buf, outImg) err = png.Encode(buf, outImg)
if err != nil {
return "", err
}
if outPath != "" { if outPath != "" {
// 写入文件 // 写入文件
f, err := os.Create(outPath) f, err := os.Create(outPath)
@ -85,9 +88,15 @@ func CreateQrCodeBs64WithLogo(content, outPath string, logoPath string, size, x,
} }
if outPath != "" { if outPath != "" {
// 写入文件 // 写入文件
f, _ := os.Create(outPath) f, err := os.Create(outPath)
if err != nil {
return "", err
}
defer f.Close() defer f.Close()
_ = png.Encode(f, outImg) err = png.Encode(f, outImg)
if err != nil {
return "", err
}
} }
return base64.StdEncoding.EncodeToString(buf.Bytes()), nil return base64.StdEncoding.EncodeToString(buf.Bytes()), nil
} }