Browse Source

wirte pic

liuyuqi-dellpc 1 year ago
parent
commit
ae2d8551fe
1 changed files with 11 additions and 0 deletions
  1. 11 0
      qr/qr.go

+ 11 - 0
qr/qr.go

@@ -4,6 +4,8 @@ import (
 	"fmt"
 	"image"
 	"log"
+	"os"
+	"path/filepath"
 
 	"github.com/skip2/go-qrcode"
 )
@@ -15,6 +17,15 @@ func RenderString(s string) {
 		log.Fatal(err)
 	}
 	fmt.Println(q.ToSmallString(false))
+	
+	dir, err1 := filepath.Abs(filepath.Dir(os.Args[0]))
+	if err1 != nil {
+		log.Fatal(err1)
+	}
+	err2 := qrcode.WriteFile(s, qrcode.Medium, 200, dir + "/tmp.png")
+	if err2 != nil {
+		panic(err2)
+	}
 }
 
 // RenderImage returns a QR code as an image.Image