-
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.
go get -u github.com/yeqown/go-qrcode
link to CODE
package main
import (
"fmt"
qrcode "github.com/yeqown/go-qrcode"
)
func main() {
qrc, err := qrcode.New("https://github.com/yeqown/go-qrcode")
if err != nil {
fmt.Printf("could not generate QRCode: %v", err)
}
// save file
if err := qrc.Save("../testdata/repo-qrcode.jpeg"); err != nil {
fmt.Printf("could not save image: %v", err)
}
}
now go-qrcode
provides some options to customize output QRCode.
// WithBgColor background color
func WithBgColor(c color.Color) ImageOption {}
// WithBgColorRGBHex background color
func WithBgColorRGBHex(hex string) ImageOption {}
// WithFgColor QR color
func WithFgColor(c color.Color) ImageOption {}
// WithFgColorRGBHex Hex string to set QR Color
func WithFgColorRGBHex(hex string) ImageOption {}
// WithLogoImage .
func WithLogoImage(img image.Image) ImageOption {}
// WithLogoImageFilePNG load image from file, PNG is required
func WithLogoImageFilePNG(f string) ImageOption {}
// WithLogoImageFileJPEG load image from file, JPEG is required
func WithLogoImageFileJPEG(f string) ImageOption {}
// WithQRWidth specify width of each qr block
func WithQRWidth(width uint8) ImageOption {}
// WithCircleShape use circle shape as rectangle(default)
func WithCircleShape() ImageOption {}
// WithCustomShape use custom shape as rectangle(default)
func WithCustomShape(shape IShape) ImageOption {}
// WithBuiltinImageEncoder option includes: JPEG_FORMAT as default, PNG_FORMAT.
// This works like WithBuiltinImageEncoder, the different between them is
// formatTyp is enumerated in (JPEG_FORMAT, PNG_FORMAT)
func WithBuiltinImageEncoder(format formatTyp) ImageOption
// WithCustomImageEncoder to use custom image encoder to encode image.Image into
// io.Writer
func WithCustomImageEncoder(encoder ImageEncoder) ImageOption
// WithBorderWidth specify the both 4 sides' border width. Notice that
// WithBorderWidth(a) means all border width use this variable `a`,
// WithBorderWidth(a, b) mean top/bottom equal to `a`, left/right equal to `b`.
// WithBorderWidth(a, b, c, d) mean top, right, bottom, left.
func WithBorderWidth(widths ...int) ImageOption
use options in New
and NewWithConfig
.
NOTICE: NewWithSpecV is deprecated
import (
qrcode "github.com/yeqown/go-qrcode"
)
// generating QR Code with source text and output image options.
qrc, _ := qrcode.New("text", WithQRWidth(x)) // x is uint8 (0 - 255)
// OR generating QR Code with specified ErrorCorrection Level and Encode Mode,
// output image options are also available.
qrc, _ := qrcode.NewWithConfig("text", config, WithQRWidth(x))
qrc.Save("path/to/qrcode.png")
following are some shots:
Jump to go.dev/github/yeqown/go-qrcode