Documentation ¶
Overview ¶
Package qrcode ... encoder.go working for data encoding
Index ¶
- Constants
- Variables
- func SetDebugMode()
- type Attribute
- type Config
- type DrawContext
- type IShape
- type ImageEncoder
- type ImageOption
- func WithBgColor(c color.Color) ImageOption
- func WithBgColorRGBHex(hex string) ImageOption
- func WithBorderWidth(widths ...int) ImageOption
- func WithBuiltinImageEncoder(format formatTyp) ImageOption
- func WithCircleShape() ImageOption
- func WithCustomImageEncoder(encoder ImageEncoder) ImageOption
- func WithCustomShape(shape IShape) ImageOption
- func WithFgColor(c color.Color) ImageOption
- func WithFgColorRGBHex(hex string) ImageOption
- func WithLogoImage(img image.Image) ImageOption
- func WithLogoImageFileJPEG(f string) ImageOption
- func WithLogoImageFilePNG(f string) ImageOption
- func WithQRWidth(width uint8) ImageOption
- type QRCode
Constants ¶
const ( // a value of EncModeAuto will trigger a detection of the letter set from the input data, EncModeAuto = 0 // EncModeNone mode ... EncModeNone encMode = 1 << iota // EncModeNumeric mode ... EncModeNumeric // EncModeAlphanumeric mode ... EncModeAlphanumeric // EncModeByte mode ... EncModeByte // EncModeJP mode ... EncModeJP )
const ( // JPEG_FORMAT as default output file format. JPEG_FORMAT formatTyp = iota // PNG_FORMAT . PNG_FORMAT )
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 )
Variables ¶
var (
ErrInvalidStateOfQRCode = fmt.Errorf("invalid state of qrcode")
)
Functions ¶
Types ¶
type Attribute ¶ added in v1.5.9
type Attribute struct {
// width and height of image
W, H int
// in the order of "top, right, bottom, left"
Borders [4]int
// the length of block edges
BlockWidth int
}
Attribute contains basic information of generated image.
type Config ¶ added in v1.5.7
type Config = outputEncodingOption
Config alias of outputEncodingOption.
func DefaultConfig ¶ added in v1.5.7
func DefaultConfig() *Config
DefaultConfig with EncMode = EncModeAuto, EcLevel = ErrorCorrectionQuart
type DrawContext ¶ added in v1.4.0
DrawContext is a rectangle area
func (*DrawContext) Color ¶ added in v1.5.3
func (dc *DrawContext) Color() color.Color
Color returns the color which should be fill into the shape. Note that if you're not using this color but your coded color.Color, some ImageOption functions those set foreground color would take no effect.
func (*DrawContext) Edge ¶ added in v1.5.3
func (dc *DrawContext) Edge() (width, height int)
Edge returns width and height of each shape could take at most.
func (*DrawContext) UpperLeft ¶ added in v1.5.3
func (dc *DrawContext) UpperLeft() image.Point
UpperLeft returns the point which indicates the upper left position.
type IShape ¶ added in v1.4.0
type IShape interface { // Draw to fill the IShape of qrcode. Draw(ctx *DrawContext) // DrawFinder to fill the finder pattern of QRCode, what's finder? google it for more information. DrawFinder(ctx *DrawContext) }
type ImageEncoder ¶ added in v1.5.0
type ImageEncoder interface { // Encode specify which format to encode image into w io.Writer. Encode(w io.Writer, img image.Image) error }
ImageEncoder is an interface which describes the rule how to encode image.Image into io.Writer
type ImageOption ¶ added in v1.3.0
type ImageOption interface {
// contains filtered or unexported methods
}
func WithBgColor ¶ added in v1.3.0
func WithBgColor(c color.Color) ImageOption
WithBgColor background color
func WithBgColorRGBHex ¶ added in v1.3.0
func WithBgColorRGBHex(hex string) ImageOption
WithBgColorRGBHex background color
func WithBorderWidth ¶ added in v1.5.8
func WithBorderWidth(widths ...int) 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 WithBuiltinImageEncoder ¶ added in v1.5.0
func WithBuiltinImageEncoder(format formatTyp) 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 WithCircleShape ¶ added in v1.4.0
func WithCircleShape() ImageOption
WithCircleShape use circle shape as rectangle(default)
func WithCustomImageEncoder ¶ added in v1.5.0
func WithCustomImageEncoder(encoder ImageEncoder) ImageOption
WithCustomImageEncoder to use custom image encoder to encode image.Image into io.Writer
func WithCustomShape ¶ added in v1.4.0
func WithCustomShape(shape IShape) ImageOption
WithCustomShape use custom shape as rectangle(default)
func WithFgColorRGBHex ¶ added in v1.3.0
func WithFgColorRGBHex(hex string) ImageOption
WithFgColorRGBHex Hex string to set QR Color
func WithLogoImage ¶ added in v1.3.0
func WithLogoImage(img image.Image) ImageOption
WithLogoImage image should only has 1/5 width of QRCode at most
func WithLogoImageFileJPEG ¶ added in v1.3.0
func WithLogoImageFileJPEG(f string) ImageOption
WithLogoImageFileJPEG load image from file, jpeg is required. image should only has 1/5 width of QRCode at most
func WithLogoImageFilePNG ¶ added in v1.3.0
func WithLogoImageFilePNG(f string) ImageOption
WithLogoImageFilePNG load image from file, PNG is required. image should only has 1/5 width of QRCode at most
func WithQRWidth ¶ added in v1.3.0
func WithQRWidth(width uint8) ImageOption
WithQRWidth specify width of each qr block
type QRCode ¶
type QRCode struct {
// contains filtered or unexported fields
}
QRCode contains fields to generate QRCode matrix, outputImageOptions to Draw image, etc.
func New ¶
func New(text string, opts ...ImageOption) (*QRCode, error)
New generate a QRCode struct to create
func NewWithConfig ¶ added in v1.5.7
func NewWithConfig(text string, encOpts *Config, opts ...ImageOption) (*QRCode, error)
NewWithConfig generate a QRCode struct with specified `ver`(QR version) and `ecLv`(Error Correction level)
func NewWithSpecV ¶
func NewWithSpecV(text string, ver int, ecLv ecLevel, opts ...ImageOption) (*QRCode, error)
NewWithSpecV generate a QRCode struct with specified `ver`(QR version) and `ecLv`(Error Correction level) Deprecated
func (*QRCode) Attribute ¶ added in v1.5.9
Attribute pre-calculate attribute of QR Code image, before actually draw it into image. avoid raising an error, you should use New and likely functions to initialize *QRCode.