qrcode

package
v1.87.5 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

QR Code to SVG

This package is a copy of https://github.com/aaronarduino/goqrsvg with the difference of creating the svg with class attribute instead of inline style:

s.Rect(currX, currY, qs.blockSize, qs.blockSize, "class=\"color\"")

and not

s.Rect(currX, currY, qs.blockSize, qs.blockSize, "fill:black;stroke:none")

This allows the svg to be styled by css more easily and does not compromise Content Security Policy (CSP).

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QrSVG

type QrSVG struct {
	// contains filtered or unexported fields
}

QrSVG holds the data related to the size, location, and block size of the QR Code. Holds unexported fields.

func NewQrSVG

func NewQrSVG(qr barcode.Barcode, blockSize int) QrSVG

NewQrSVG contructs a QrSVG struct. It takes a QR Code in the form of barcode.Barcode and sets the "pixel" or block size of QR Code in the SVG file.

Example
s := svg.New(os.Stdout)

// Create the barcode
qrCode, _ := qr.Encode("Hello World", qr.M, qr.Auto)

// Write QR code to SVG
qs := NewQrSVG(qrCode, 5)
qs.StartQrSVG(s)
qs.WriteQrSVG(s)

s.End()
Output:

func (*QrSVG) SetStartPoint

func (qs *QrSVG) SetStartPoint(x, y int)

SetStartPoint sets the top left start point of QR Code. This takes an X and Y value and then adds four white "blocks" to create the "quiet zone" around the QR Code.

func (*QrSVG) StartQrSVG

func (qs *QrSVG) StartQrSVG(s *svg.SVG)

StartQrSVG creates a start for writing an SVG file that only contains a barcode. This is similar to the svg.Start() method. This fucntion should only be used if you only want to write a QR code to the SVG. Otherwise use the regular svg.Start() method to start your SVG file.

func (*QrSVG) WriteQrSVG

func (qs *QrSVG) WriteQrSVG(s *svg.SVG) error

WriteQrSVG writes the QR Code to SVG.

Jump to

Keyboard shortcuts

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