diff --git a/utils/qrcode/creator.go b/utils/qrcode/creator.go index 2dfdf312..48734c6e 100644 --- a/utils/qrcode/creator.go +++ b/utils/qrcode/creator.go @@ -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