qrsvg

package module
v0.0.0-...-9525ec9 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 5 Imported by: 3

README

svg-qr-code

Go Reference Build Status codecov Go Report Card

Description

svg-qr-code is a Go module that encodes QR Codes in SVG format

Installation

This module can be installed with the go get command:

go get -u github.com/wamuir/svg-qr-code

Example Usage


  qr, err := qrsvg.New("https://github.com/wamuir/svg-qr-code")
  if err != nil {
     panic(err)
  }

  // qr satisfies fmt.Stringer interface (or call qr.String() for a string)
  fmt.Println(qr)

Example Result

Quick Response (QR) Code

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	X      int    `xml:"x,attr"`
	Y      int    `xml:"y,attr"`
	Width  int    `xml:"width,attr"`
	Height int    `xml:"height,attr"`
	Fill   string `xml:"fill,attr"`
}

Block is a color block in the rendered QR code.

type QR

type QR struct {
	Code        *qrcode.QRCode // underlying QR Code
	Blocksize   int            // size of each block in pixels, default = 16 pixels
	Borderwidth int            // size of the border in blocks, default = 4 blocks
	Borderfill  color.Color    // fill color for the border
}

QR holds a QR Code (from github.com/skip2/go-qrcode) and SVG settings.

func New

func New(s string) (*QR, error)

New returns the QR for the provided string, with default settings for blocksize, borderwidth and background color. Call .String() to obtain the SVG string.

func (*QR) SVG

func (q *QR) SVG() *SVG

SVG returns the vector representation of a QR code, as a Go struct. This could, for instance, be marshaled with encoding/xml.

func (*QR) String

func (q *QR) String() string

String() returns the QR as an SVG string and satisfies the fmt.Stringer interface.

type SVG

type SVG struct {
	XMLName xml.Name `xml:"svg"`
	NS      string   `xml:"xmlns,attr"`
	Width   int      `xml:"width,attr"`
	Height  int      `xml:"height,attr"`
	Style   string   `xml:"style,attr"`
	Blocks  []Block  `xml:"rect"`
}

SVG is the vector representation of a QR code, as a Go struct.

func (*SVG) String

func (s *SVG) String() string

String() returns the SVG as a string and satisfies the fmt.Stringer interface.

Jump to

Keyboard shortcuts

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