go生成二维码:
go get -u github.com/skip2/go-qrcode
package main
import (
"github.com/skip2/go-qrcode"
)
func main(){
//最常见的二维码
q, err := qrcode.New("https://www.buruyouni.com/?id=3123123123213113213", qrcode.Medium)
if err != nil {
panic(err)
}
q.DisableBorder = true//去掉边框
//70*70一般手机最小能扫描的尺寸了 输出的文件名称:output.png
err = q.WriteFile(70, "output.png")
if err != nil {
panic(err)
}
//带颜色的二维码
q2,_ := qrcode.New("https://buruyouni.com/?id=sdasdasda", qrcode.Medium)
q2.DisableBorder = true
q2.BackgroundColor = colornames.Lightskyblue
q2.ForegroundColor = colornames.Lightgray
err = q2.WriteFile(80,"color.png")
fmt.Println(err)
}
go识别二维码:
go get -u github.com/tuotoo/qrcode
package main
import (
"fmt"
"os"
"github.com/tuotoo/qrcode"
)
func main() {
fi, err := os.Open("qrcode.jpg") // 默认到$GOPATH/src/ 下找
if err != nil {
fmt.Println(err.Error())
return
}
defer fi.Close()
qrmatrix, err := qrcode.Decode(fi)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(qrmatrix.Content)
}