- Normally generate QR code across
version 1
toversion 40
. - Automatically analyze QR version by source text.
- Specifying cell shape allowably with
WithCustomShape
,WithCircleShape
(default isrectangle
) - Specifying output file's format with
WithBuiltinImageEncoder
,WithCustomImageEncoder
(default isJPEG
) - Not only shape of cell, but also color of QR Code background and foreground color.
-
WithLogoImage
,WithLogoImageFilePNG
,WithLogoImageFileJPEG
help you add an icon at the central of QR Code. -
WithBorderWidth
allows to specify any width of 4 sides around the qrcode. -
WebAssembly
support, check out the Example and README for more detail. - support Halftone QR Codes, check out the Example.
go get -u github.com/yeqown/go-qrcode/v2
link to CODE
package main
import (
"github.com/yeqown/go-qrcode/v2"
"github.com/yeqown/go-qrcode/writer/standard"
)
func main() {
qrc, err := qrcode.New("https://github.com/yeqown/go-qrcode")
if err != nil {
fmt.Printf("could not generate QRCode: %v", err)
return
}
w, err := standard.New("../assets/repo-qrcode.jpeg")
if err != nil {
fmt.Printf("standard.New failed: %v", err)
return
}
// save file
if err = qrc.Save(w); err != nil {
fmt.Printf("could not save image: %v", err)
}
}
const (
// EncModeNone mode ...
EncModeNone encMode = 1 << iota
// EncModeNumeric mode ...
EncModeNumeric
// EncModeAlphanumeric mode ...
EncModeAlphanumeric
// EncModeByte mode ...
EncModeByte
// EncModeJP mode ...
EncModeJP
)
// WithEncodingMode sets the encoding mode.
func WithEncodingMode(mode encMode) EncodeOption {}
const (
// ErrorCorrectionLow :Level L: 7% error recovery.
ErrorCorrectionLow ecLevel = iota + 1
// ErrorCorrectionMedium :Level M: 15% error recovery. Good default choice.
ErrorCorrectionMedium
// ErrorCorrectionQuart :Level Q: 25% error recovery.
ErrorCorrectionQuart
// ErrorCorrectionHighest :Level H: 30% error recovery.
ErrorCorrectionHighest
)
// WithErrorCorrectionLevel sets the error correction level.
func WithErrorCorrectionLevel(ecLevel ecLevel) EncodeOption {}
following are some shots:
- Standard Writer, prints QRCode into file and stream
- Terminal Writer, prints QRCode into terminal
- File Writer, prints QRCode into files
- Compressed Writer, It's generated on a very small scale
Of course, you can also code your own writer, just implement Writer interface.
go-qrcode.v2
is a major upgrade from v1, and it is not backward compatible. v2
redesigned
the API, and it is more flexible and powerful. Features are split into different modules (according to functionality).
- github.com/yeqown/go-qrcode/v2 core
- github.com/yeqown/go-qrcode/writer/standard writer/imageFile
- github.com/yeqown/go-qrcode/writer/terminal writer/terminal
Check example/migrating-from-v1 for more details.