qrsvg

package
v0.0.0-...-642df0c Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: BSD-3-Clause, MIT, MIT Imports: 7 Imported by: 0

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 EBlock

type EBlock struct {
	X      int     `xml:"cx,attr"`
	Y      int     `xml:"cy,attr"`
	Width  float32 `xml:"rx,attr"`
	Height float32 `xml:"ry,attr"`
	Fill   string  `xml:"fill,attr"`
}

type QR

type QR struct {
	Text        string      // text of the QR
	Blocksize   uint8       // size of each block in pixels, default = 16 pixels
	Borderwidth uint8       // size of the border in blocks, default = 4 blocks
	Borderfill  color.Color // fill color for the border
	UseDots     bool        // draw using dots or squares
	Svg         string      // the SVG code
	// contains filtered or unexported fields
}

QR holds a QR Code (from github.com/unix-world/smartgo/markup/svg-qrcode) and SVG settings.

func New

func New(s string, level string, fgColor string, bgColor string, useDots bool, blockSize uint8, borderWidth uint8) (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.

type RBlock

type RBlock 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 SVG

type SVG struct {
	XMLName xml.Name `xml:"svg"`
	NS      string   `xml:"xmlns,attr"`
	Render  string   `xml:"shape-rendering,attr"`
	Width   uint     `xml:"width,attr"`
	Height  uint     `xml:"height,attr"`
	Style   string   `xml:"style,attr"`
	RBlocks []RBlock `xml:"rect"`
	EBlocks []EBlock `xml:"ellipse"`
}

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

Jump to

Keyboard shortcuts

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