getqr

package module
v0.0.0-...-c618287 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2022 License: Apache-2.0 Imports: 12 Imported by: 1

README

QR Code encoder

Documentation

Index

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 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() To serve over HTTP, remember to send a Content-Type: image/png header

func WriteColorFile

func WriteColorFile(content string, level RecoveryLevel, size int, background,
	foreground color.Color, filename string) error

Encodes, then writes a QR Code to the given filename in PNG format Allows you to 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

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 {
	Content         string        // Original content encoded
	Level           RecoveryLevel // QR Code type
	VersionNumber   int
	BackgroundColor color.Color // User settable drawing options
	ForegroundColor color.Color
	DisableBorder   bool // Disable the QR Code border
	Border          bool // QR Code border. True — borders are enabled
	// contains filtered or unexported fields
}

func New

func New(content string, level RecoveryLevel) (*QRCode, error)

Constructs a QR Code. An error occurs if the content is too long

func NewWithForcedVersion

func NewWithForcedVersion(content string, version int, level RecoveryLevel) (*QRCode, error)

Constructs a QR code of a specific version. An error occurs in case of invalid version

func (*QRCode) Bitmap

func (q *QRCode) Bitmap() [][]bool

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

func (q *QRCode) Image(size int) 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

func (q *QRCode) PNG(size int) ([]byte, error)

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

func (q *QRCode) ToSmallString(inverseColor bool) string

Produces a multi-line string that forms a QR-code image, a factor two smaller in x and y then ToString

func (*QRCode) ToString

func (q *QRCode) ToString(inverseColor bool) string

Produces a multi-line string that forms a QR-code image

func (*QRCode) Write

func (q *QRCode) Write(size int, out io.Writer) error

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

func (q *QRCode) WriteFile(size int, filename string) error

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
const (
	Low     RecoveryLevel = iota // Level L: 7% error recovery
	Medium                       // Level M: 15% error recovery. Good default choice
	High                         // Level Q: 25% error recovery
	Highest                      // Level H: 30% error recovery
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL