This commit is contained in:
laodaming 2023-06-08 18:22:27 +08:00
parent 48879a8b29
commit 20987b5e1b

View File

@ -28,13 +28,15 @@ func CreateQrCodeBs64WithLogo(content, outPath string, logoPath string, size, x,
//无logo
if logoPath == "" {
//图像偏移
draw.Draw(outImg, outImg.Bounds().Add(image.Pt(x, y)), outImg, outImg.Bounds().Min, draw.Src)
_ = png.Encode(buf, qrcodeImg)
if x != 0 || y != 0 {
draw.Draw(outImg, outImg.Bounds().Add(image.Pt(x, y)), qrcodeImg, outImg.Bounds().Min, draw.Src)
}
_ = png.Encode(buf, outImg)
if outPath != "" {
// 写入文件
f, _ := os.Create(outPath)
defer f.Close()
err = png.Encode(f, qrcodeImg)
err = png.Encode(f, outImg)
if err != nil {
return "", err
}
@ -71,7 +73,9 @@ func CreateQrCodeBs64WithLogo(content, outPath string, logoPath string, size, x,
offset := image.Pt((outImg.Bounds().Max.X-transparentImg.Bounds().Max.X)/2, (outImg.Bounds().Max.Y-transparentImg.Bounds().Max.Y)/2)
draw.Draw(outImg, outImg.Bounds().Add(offset), transparentImg, image.Pt(0, 0), draw.Over)
//图像偏移
draw.Draw(outImg, outImg.Bounds().Add(image.Pt(x, y)), outImg, outImg.Bounds().Min, draw.Src)
if x != 0 || y != 0 {
draw.Draw(outImg, outImg.Bounds().Add(image.Pt(x, y)), qrcodeImg, outImg.Bounds().Min, draw.Src)
}
err = png.Encode(buf, outImg)
if err != nil {
return "", err