Documentation ¶
Index ¶
- func Encode(content string, level RecoveryLevel, size int) ([]byte, error)
- func WriteColorFile(content string, level RecoveryLevel, size int, ...) error
- func WriteFile(content string, level RecoveryLevel, size int, filename string) error
- type QRCode
- func (q *QRCode) Bitmap() [][]bool
- func (q *QRCode) Image(size int) image.Image
- func (q *QRCode) PNG(size int) ([]byte, error)
- func (q *QRCode) ToSmallString(inverseColor bool) string
- func (q *QRCode) ToString(inverseColor bool) string
- func (q *QRCode) Write(size int, out io.Writer) error
- func (q *QRCode) WriteFile(size int, filename string) error
- type RecoveryLevel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Encode ¶
func Encode(content string, level RecoveryLevel, size int) ([]byte, error)
Encode a QR Code and return a raw PNG image
func WriteColorFile ¶
func WriteColorFile(content string, level RecoveryLevel, size int, background, foreground color.Color, filename string) error
WriteColorFile encodes, then writes a QR Code to the given filename in PNG format. With WriteColorFile you can also specify the colors you want to use.
size is both the image width and height in pixels. If size is too small then a larger image is silently written. Negative values for size cause a variable sized image to be written: See the documentation for Image().
func WriteFile ¶
func WriteFile(content string, level RecoveryLevel, size int, filename string) error
WriteFile encodes, then writes a QR Code to the given filename in PNG format.
size is both the image width and height in pixels. If size is too small then a larger image is silently written. Negative values for size cause a variable sized image to be written: See the documentation for Image().
Types ¶
type QRCode ¶
type QRCode struct { // Original content encoded. Content string // QR Code type Level RecoveryLevel VersionNumber int // User settable drawing options. ForegroundColor color.Color BackgroundColor color.Color // Disable the QR Code border. DisableBorder bool // contains filtered or unexported fields }
QRCode represents a valid encoded QRCode
func New ¶
func New(content string, level RecoveryLevel) (*QRCode, error)
New constructs a QRCode.
var q *qrcode.QRCode q, err := qrcode.New("my content", qrcode.Medium)
An error occurs if the content is too long.
func NewWithForcedVersion ¶
func NewWithForcedVersion(content string, version int, level RecoveryLevel) (*QRCode, error)
NewWithForcedVersion constructs a QRCode of a specific version.
var q *qrcode.QRCode q, err := qrcode.NewWithForcedVersion("my content", 25, qrcode.Medium)
An error occurs in case of invalid version.
func (*QRCode) Bitmap ¶
Bitmap returns the QR Code as a 2D array of 1-bit pixels.
bitmap[y][x] is true if the pixel at (x, y) is set.
The bitmap includes the required "quiet zone" around the QR Code to aid decoding.
func (*QRCode) Image ¶
Image returns the QR Code as an image.Image.
A positive size sets a fixed image width and height (e.g. 256 yields an 256x256px image).
Depending on the amount of data encoded, fixed size images can have different amounts of padding (white space around the QR Code). As an alternative, a variable sized image can be generated instead:
A negative size causes a variable sized image to be returned. The image returned is the minimum size required for the QR Code. Choose a larger negative number to increase the scale of the image. e.g. a size of -5 causes each module (QR Code "pixel") to be 5px in size.
func (*QRCode) PNG ¶
PNG returns the QR Code as a PNG image.
size is both the image width and height in pixels. If size is too small then a larger image is silently returned. Negative values for size cause a variable sized image to be returned: See the documentation for Image().
func (*QRCode) ToSmallString ¶
ToSmallString produces a multi-line string that forms a QR-code image, a factor two smaller in x and y then ToString.
func (*QRCode) Write ¶
Write writes the QR Code as a PNG image to io.Writer.
size is both the image width and height in pixels. If size is too small then a larger image is silently written. Negative values for size cause a variable sized image to be written: See the documentation for Image().
func (*QRCode) WriteFile ¶
WriteFile writes the QR Code as a PNG image to the specified file.
size is both the image width and height in pixels. If size is too small then a larger image is silently written. Negative values for size cause a variable sized image to be written: See the documentation for Image().
type RecoveryLevel ¶
type RecoveryLevel int
Error detection/recovery capacity.
There are several levels of error detection/recovery capacity. Higher levels of error recovery are able to correct more errors, with the trade-off of increased symbol size.
const ( // Level L: 7% error recovery. Low RecoveryLevel = iota // Level M: 15% error recovery. Good default choice. Medium // Level Q: 25% error recovery. High // Level H: 30% error recovery. Highest )