forked from yeqown/go-qrcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (60 loc) · 1.33 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
qrv2 "github.com/yeqown/go-qrcode/v2"
"github.com/yeqown/go-qrcode/writer/standard"
qrv1 "github.com/yeqown/go-qrcode"
)
func main() {
// draw a QRCode image with
// - "https://github.com/yeqown/go-qrcode" source text
// - circle shape
// - blue foreground color
// - white background color
// - 20 pixel block width
// - 20 pixel border width
// - The Highest error correction level
v1()
v2()
}
func v1() {
encodeConfig := &qrv1.Config{
EcLevel: qrv1.ErrorCorrectionHighest,
EncMode: qrv1.EncModeAuto,
}
qrc, err := qrv1.NewWithConfig("https://github.com/yeqown/go-qrcode", encodeConfig,
qrv1.WithCircleShape(),
qrv1.WithFgColorRGBHex("#0000ff"),
qrv1.WithBgColorRGBHex("#ffffff"),
qrv1.WithQRWidth(20),
qrv1.WithBorderWidth(20),
)
if err != nil {
panic(err)
}
err = qrc.Save("v1.jpeg")
if err != nil {
panic(err)
}
}
func v2() {
qrc, err := qrv2.NewWith("https://github.com/yeqown/go-qrcode",
qrv2.WithErrorCorrectionLevel(qrv2.ErrorCorrectionHighest),
)
if err != nil {
panic(err)
}
w, err := standard.New("v2.jpeg",
standard.WithCircleShape(),
standard.WithFgColorRGBHex("#0000ff"),
standard.WithBgColorRGBHex("#ffffff"),
standard.WithQRWidth(20),
standard.WithBorderWidth(20),
)
if err != nil {
panic(err)
}
err = qrc.Save(w)
if err != nil {
panic(err)
}
}