Documentation
¶
Overview ¶
Package qr can be used to create QR barcodes.
Index ¶
- Variables
- func Encode(content string, level ErrorCorrectionLevel, mode Encoding) (barcode.Barcode, error)
- type BackgroundOption
- type Canvas
- type CanvasOption
- type Code
- func (qr *Code) At(x, y int) color.Color
- func (qr *Code) Bounds() image.Rectangle
- func (qr *Code) ColorModel() color.Model
- func (qr *Code) Content() string
- func (qr *Code) Dimension() int
- func (qr *Code) Get(x, y int) bool
- func (qr *Code) Metadata() barcode.Metadata
- func (qr *Code) Set(x, y int, val bool)
- type Encoding
- type ErrorCorrectionLevel
- type Filter
- type HalftoneOption
- type ImageOption
- type Option
- func WithBackgroundOption(backgroundOption BackgroundOption) Option
- func WithCornerDotOption(cornerDotOption feature.CornerDotOption) Option
- func WithCornerSquareOption(cornerSquareOption feature.CornerSquareOption) Option
- func WithDotOption(dotOption feature.DotOption) Option
- func WithHalftoneOption(halftoneOption HalftoneOption) Option
- func WithImageOption(imageOption ImageOption) Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrValidGradient = errors.New("invalid gradient") ErrInvalidBarcode = errors.New("invalid barcode") )
View Source
var DotMask = [][]int{
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
}
View Source
var ErrorCorrectionPercents = map[ErrorCorrectionLevel]float64{
L: 0.07,
M: 0.15,
Q: 0.25,
H: 0.3,
}
View Source
var QrTypes = []int{0, 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}
View Source
var SquareMask = [][]int{
{1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1},
}
Functions ¶
func Encode ¶
Encode returns a QR barcode with the given content, error correction level and uses the given encoding
Example ¶
f, _ := os.Create("QRCode.png") defer f.Close() qrcode, err := Encode("hello world", L, Auto) if err != nil { fmt.Println(err) } else { code, err := barcode.Scale(qrcode, 100, 100) if err != nil { fmt.Println(err) } else { png.Encode(f, code) } }
Output:
Types ¶
type BackgroundOption ¶ added in v1.2.0
type CanvasOption ¶ added in v1.2.0
type CanvasOption struct { Width int Height int Margin int TypeNumber int Encoding Encoding ErrorCorrectionLevel ErrorCorrectionLevel DotOption feature.DotOption CornerSquareOption feature.CornerSquareOption CornerDotOption feature.CornerDotOption BackgroundOption BackgroundOption Image string ImageOption ImageOption HalftoneOption HalftoneOption }
func (CanvasOption) Merge ¶ added in v1.2.0
func (o CanvasOption) Merge(other CanvasOption)
type Code ¶ added in v1.3.0
type Code struct {
// contains filtered or unexported fields
}
func (*Code) ColorModel ¶ added in v1.3.0
type Encoding ¶
type Encoding byte
Encoding mode for QR Codes.
const ( // Auto will choose ths best matching encoding Auto Encoding = iota // Numeric encoding only encodes numbers [0-9] Numeric // AlphaNumeric encoding only encodes uppercase letters, numbers and [Space], $, %, *, +, -, ., /, : AlphaNumeric // Unicode encoding encodes the string as utf-8 Unicode )
type ErrorCorrectionLevel ¶
type ErrorCorrectionLevel byte
ErrorCorrectionLevel indicates the amount of "backup data" stored in the QR code
const ( // L recovers 7% of data L ErrorCorrectionLevel = iota // M recovers 15% of data M // Q recovers 25% of data Q // H recovers 30% of data H )
func (ErrorCorrectionLevel) String ¶
func (ecl ErrorCorrectionLevel) String() string
type HalftoneOption ¶ added in v1.2.0
type ImageOption ¶ added in v1.2.0
type Option ¶ added in v1.2.0
type Option func(o *CanvasOption)
func WithBackgroundOption ¶ added in v1.2.0
func WithBackgroundOption(backgroundOption BackgroundOption) Option
func WithCornerDotOption ¶ added in v1.2.0
func WithCornerDotOption(cornerDotOption feature.CornerDotOption) Option
func WithCornerSquareOption ¶ added in v1.2.0
func WithCornerSquareOption(cornerSquareOption feature.CornerSquareOption) Option
func WithDotOption ¶ added in v1.2.0
func WithHalftoneOption ¶ added in v1.2.0
func WithHalftoneOption(halftoneOption HalftoneOption) Option
func WithImageOption ¶ added in v1.2.0
func WithImageOption(imageOption ImageOption) Option
Source Files
¶
Click to show internal directories.
Click to hide internal directories.