-
Notifications
You must be signed in to change notification settings - Fork 0
/
qrcode.go
42 lines (36 loc) · 877 Bytes
/
qrcode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package goutil
import (
"fmt"
"io"
"github.com/tuotoo/qrcode"
qrCodeGo "github.com/yeqown/go-qrcode"
)
// @Project: go-util
// @Author: houseme
// @Description:
// @File: qrcode
// @Version: 1.0.0
// @Date: 2021/4/6 00:12
// @Package goutil
// QRCodeParse 二维码图片解析
func QRCodeParse(fi io.Reader) (string, error) {
qrMatrix, err := qrcode.Decode(fi)
if err != nil {
return "", err
}
return qrMatrix.Content, nil
}
// QRCreate .
func QRCreate(text, saveToPath string, opts ...qrCodeGo.ImageOption) error {
qrc, err := qrCodeGo.New(text, opts...)
if err != nil {
fmt.Printf("could not generate QRCode: %v", err)
return err
}
// save file
if err := qrc.Save(saveToPath); err != nil {
fmt.Printf("could not save image: %v", err)
return err
}
return nil
}