Documentation ¶
Index ¶
- Constants
- Variables
- func WithOptimalSVG() func(*QrCodeImgConfig)
- func WithSVGXMLHeader(header bool) func(*QrCodeImgConfig)
- type BitBuffer
- type BitSet
- type DataTooLongException
- type Ecc
- type Mode
- type QrCode
- func (q *QrCode) GetModule(x, y int) bool
- func (q *QrCode) GetSize() int
- func (q *QrCode) PNG(config *QrCodeImgConfig, filePath string) error
- func (q *QrCode) SVG(config *QrCodeImgConfig, filePath, light, dark string) error
- func (q *QrCode) WriteAsPNG(config *QrCodeImgConfig, writer io.Writer) error
- func (q *QrCode) WriteAsSVG(config *QrCodeImgConfig, writer io.Writer, light, dark string) error
- type QrCodeImgConfig
- type QrSegment
- func MakeAlphanumeric(text string) (*QrSegment, error)
- func MakeBytes(data []byte) (*QrSegment, error)
- func MakeEci(val int) (*QrSegment, error)
- func MakeKanji(text string) (*QrSegment, error)
- func MakeNumeric(digits string) (*QrSegment, error)
- func MakeSegments(text string) ([]*QrSegment, error)
- func MakeSegmentsOptimally(text string, ecl Ecc, minVersion, maxVersion int) ([]*QrSegment, error)
Constants ¶
const ( MinVersion = 1 MaxVersion = 40 )
Minimum(1) and Maximum(40) version numbers based on the QR Code Model 2 standard
Variables ¶
var ( // Numeric mode is typically used for decimal digits (0 through 9). Numeric = newMode(0x1, 10, 12, 14) // Alphanumeric mode includes digits 0-9, uppercase letters A-Z and nine special characters. Alphanumeric = newMode(0x2, 9, 11, 13) // Byte mode can encode binary/byte data(default: ISO-8859-1) Byte = newMode(0x4, 8, 16, 16) // Byte mode: binary/byte data (default: ISO-8859-1) // Kanji mode is used for encoding Japanese Kanji characters. Kanji = newMode(0x8, 8, 10, 12) // Eci mode is designed for providing a method of extending features and functions // in bar code symbols beyond those envisioned by the original standard. Eci = newMode(0x7, 0, 0, 0) )
Predefined Mode values as defined by the QR Code standard.
Functions ¶
func WithOptimalSVG ¶ added in v0.2.6
func WithOptimalSVG() func(*QrCodeImgConfig)
WithOptimalSVG returns a function that sets the optimalSVG option to true in the provided QrCodeImgConfig.
func WithSVGXMLHeader ¶ added in v0.2.5
func WithSVGXMLHeader(header bool) func(*QrCodeImgConfig)
WithSVGXMLHeader returns a function that sets the svgXMLHeader option to true in the provided QrCodeImgConfig.
Types ¶
type BitSet ¶
type BitSet interface {
// contains filtered or unexported methods
}
BitSet defines an interface that allows manipulation of a bitset.
type DataTooLongException ¶
type DataTooLongException struct {
Msg string
}
func (*DataTooLongException) Error ¶
func (d *DataTooLongException) Error() string
type Ecc ¶
type Ecc int
Ecc is the representation of an error correction level in a QR Code symbol.
func (Ecc) FormatBits ¶
FormatBits method gets the format bits associated with the error correction level.
type Mode ¶
type Mode struct {
// contains filtered or unexported fields
}
Mode is the representation of the mode of a QR code character.
type QrCode ¶
type QrCode struct {
// contains filtered or unexported fields
}
QrCode is the representation of a QR code
func EncodeBinary ¶
EncodeBinary takes a byte array and an error correction level (ecl), converts the bytes to QR code segments and returns a QR code or an error.
func EncodeSegments ¶
func EncodeSegments(segs []*QrSegment, ecl Ecc, minVer, maxVer, mask int, boostEcl bool) (*QrCode, error)
EncodeSegments is a more flexible version of EncodeStandardSegments. It allows the specification of minVer, maxVer, mask in addition to the regular parameters. Returns a QR code object or an error.
func EncodeStandardSegments ¶
EncodeStandardSegments takes QR code segments and an error correction level, creates a standard QR code using these parameters and returns it or an error.
func EncodeText ¶
EncodeText takes a string and an error correction level (ecl), encodes the text to segments and returns a QR code or an error.
func (*QrCode) PNG ¶ added in v0.2.1
func (q *QrCode) PNG(config *QrCodeImgConfig, filePath string) error
PNG generates a PNG image file for the QR code with QrCodeImgConfig and saves it to given file path
func (*QrCode) SVG ¶ added in v0.2.2
func (q *QrCode) SVG(config *QrCodeImgConfig, filePath, light, dark string) error
SVG generates a SVG file for the QR code with QrCodeImgConfig, light, dark color and saves it to given file path
func (*QrCode) WriteAsPNG ¶ added in v0.2.4
func (q *QrCode) WriteAsPNG(config *QrCodeImgConfig, writer io.Writer) error
WriteAsPNG writes the QR code as PNG with QrCodeImgConfig to the provided io.Writer.
func (*QrCode) WriteAsSVG ¶ added in v0.2.4
WriteAsSVG writes the QR code as SVG with QrCodeImgConfig, light, dark color to the provided io.Writer.
light is the color to use for light sections of the QR code, for example, "#FFFFFF". dark is the color to use for dark sections of the QR code, for example, "#000000".
type QrCodeImgConfig ¶ added in v0.2.1
type QrCodeImgConfig struct {
// contains filtered or unexported fields
}
QrCodeImgConfig is the representation of the QR Code generation configuration
func NewQrCodeImgConfig ¶ added in v0.2.1
func NewQrCodeImgConfig(scale int, border int, options ...func(config *QrCodeImgConfig)) *QrCodeImgConfig
NewQrCodeImgConfig is used to create a QR code generation config with the provided scale of image(scale), border of image(border), and the default light and dark color are white and black.
func (*QrCodeImgConfig) Dark ¶ added in v0.2.1
func (q *QrCodeImgConfig) Dark() color.Color
Dark gets dark color from QrCodeImgConfig
func (*QrCodeImgConfig) Light ¶ added in v0.2.1
func (q *QrCodeImgConfig) Light() color.Color
Light gets light color from QrCodeImgConfig
func (*QrCodeImgConfig) SetDark ¶ added in v0.2.1
func (q *QrCodeImgConfig) SetDark(dark color.Color)
SetDark sets dark color in the QrCodeImgConfig
func (*QrCodeImgConfig) SetLight ¶ added in v0.2.1
func (q *QrCodeImgConfig) SetLight(light color.Color)
SetLight sets light color in the QrCodeImgConfig
func (*QrCodeImgConfig) Valid ¶ added in v0.2.2
func (q *QrCodeImgConfig) Valid() error
type QrSegment ¶
type QrSegment struct {
// contains filtered or unexported fields
}
QrSegment is the representation of a segment of a QR code.
func MakeAlphanumeric ¶
MakeAlphanumeric converts a string into a QR code segment in Alphanumeric mode It returns an error if the string contains non-alphanumeric characters.
func MakeBytes ¶
MakeBytes converts a byte slice into a QR segment in Byte mode. It returns an error if the input data is nil.
func MakeEci ¶
MakeEci converts an integer into a QR code segment in Eci mode It returns an error if the integer value is out of range.
func MakeKanji ¶
MakeKanji converts a string into a QR code segment in Kanji mode It returns an error if the string contains non-kanji characters.
func MakeNumeric ¶
MakeNumeric converts a string of digits into a QR code segment in Numeric mode It returns an error if the string contains non-numeric characters.
func MakeSegments ¶
MakeSegments converts data into QR segments based on the mode of text (Numeric, Alphanumeric or Byte, etc).
func MakeSegmentsOptimally ¶
MakeSegmentsOptimally takes a string and error correction level, and attempts to make QR segments in the most efficient way possible. It validates the version range and converts the input text into code points. Then, it loops through each version, attempting to make segments until the data fits within the capacity of the version. Returns an array of pointers to QrSegment or an error.