qrsvg

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

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 5 Imported by: 7 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func WithBlocksize

func WithBlocksize(blocksize int) func(*opts)

func WithBorderwidth

func WithBorderwidth(borderwidth int) func(*opts)

func WithRecoveryLevel

func WithRecoveryLevel(level RecoveryLevel) func(*opts)

func WithStyle

func WithStyle(style string) func(*opts)

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"`
	Class  string `xml:"class,attr,omitempty"`
}

Block is a color block in the rendered QR code.

type CDataString

type CDataString struct {
	Value string `xml:",cdata"`
}

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
	Style       *CDataString   // css styling
}

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

func New

func New(s string, options ...func(*opts)) (*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   *CDataString `xml:"style,omitempty"`
	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
⌂ 换网址