qrw

package module
v0.0.0-...-6e56aa4 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 8 Imported by: 0

README

QRCode Writer

Output QR codes for Go

Build Status Coverage Status GoDoc

Features

  • Output to text
    • two characters as a block
    • half character as a block
  • Output to terminal
    • bash
    • zsh
  • Output to file
    • text
    • png
    • jpeg

Example

As shown in the figure, you can get started quickly with the following example:

image

BlockWriter

Show a QR block by two characters.

Output to io.Writer:
BlockWrite(os.Stdout, L, "Hello world!")
Output to file:
BlockWriteFile("file_path", L, "Hello world!")
HalfBlockWriter

Show a QR block by half character.

Output to io.Writer:
HalfBlockWrite(os.Stdout, L, "Hello world!")
Output to file:
HalfBlockWriteFile("file_path", L, "Hello world!")

Usage

Common functions:

func BlockWrite(io.Writer, Level, string) error
func BlockWriteFile(string, Level, string) error
func HalfBlockWrite(io.Writer, Level, string) error
func HalfBlockWriteFile(string, Level, string) error
func Bash(Level, string) error
func PNG(string, Level, string) error
func JPEG(string, Level, string) error

See document.

Level(error correction level)

From least to most tolerant of errors:

  • L 20% redundant
  • M 38% redundant
  • Q 55% redundant
  • H 65% redundant

The definitions come from rsc/qr.

Install

go get -u github.com/WindomZ/qrw

Documentation

Index

Constants

View Source
const (
	// L low tolerant of errors
	L = Level(qr.L) // 20% redundant
	// M middle tolerant of errors
	M = Level(qr.M) // 38% redundant
	// Q half tolerant of errors
	Q = Level(qr.Q) // 55% redundant
	// H high tolerant of errors
	H = Level(qr.H) // 65% redundant
)
View Source
const QuietZoneBlocks = 4

QuietZoneBlocks is the default number of QR quiet zone blocks

Variables

This section is empty.

Functions

func Bash

func Bash(l Level, text string) error

Bash generates a QR Code with bash color and output to Unix shell. Two characters as a QR block.

func BlockWrite

func BlockWrite(w io.Writer, l Level, text string) error

BlockWrite generates a QR Code with Unicode characters and output to io.Writer. Two characters as a QR block.

func BlockWriteFile

func BlockWriteFile(filename string, l Level, text string) error

BlockWriteFile generates a QR Code with Unicode characters and output to a file named by filename. Two characters as a QR block.

func HalfBash

func HalfBash(l Level, text string) error

HalfBash generates a QR Code with bash color and output to Unix shell. Half character as a QR block.

func HalfBlockWrite

func HalfBlockWrite(w io.Writer, l Level, text string) error

HalfBlockWrite generates a QR Code with Unicode Block Elements and output to io.Writer. Half character as a QR block.

func HalfBlockWriteFile

func HalfBlockWriteFile(filename string, l Level, text string) error

HalfBlockWriteFile generates a QR Code with Unicode Block Elements and output to a file named by filename. Half character as a QR block.

func JPEG

func JPEG(filename string, l Level, text string) error

JPEG generates a QR Code and output to a JPEG image file named by filename.

func PNG

func PNG(filename string, l Level, text string) error

PNG generates a QR Code and output to a PNG image file named by filename.

Types

type BashWriter

type BashWriter struct {
	Writer
	Buffer *bytes.Buffer
	BlockB []byte
	BlockW []byte
}

BashWriter implements QR Writer by 'echo' command, output to terminal stdout.

func NewBashWriter

func NewBashWriter(l Level, w io.Writer) *BashWriter

NewBashWriter returns a BashWriter instance after initialization.

func (*BashWriter) Invert

func (w *BashWriter) Invert() *BashWriter

Invert the color of block.

func (*BashWriter) QR

func (w *BashWriter) QR(text string) error

QR encode text at the given error correction level, and write to the given io.Writer.

func (*BashWriter) Write

func (w *BashWriter) Write(p []byte) (err error)

Write the io.Writer wraps the basic Write method.

type BlockWriter

type BlockWriter struct {
	Writer
	BlockB []byte
	BlockW []byte
}

BlockWriter implements QR Writer use Unicode characters, output to text.

func NewBlockWriter

func NewBlockWriter(l Level, w io.Writer) *BlockWriter

NewBlockWriter returns a BlockWriter instance after initialization.

func (*BlockWriter) Invert

func (w *BlockWriter) Invert() *BlockWriter

Invert the color of block.

func (*BlockWriter) QR

func (w *BlockWriter) QR(text string) error

QR encode text at the given error correction level, and write to the given io.Writer.

func (*BlockWriter) QRFile

func (w *BlockWriter) QRFile(filename, text string) error

QRFile encode text at the given error correction level, and rewrite to a file named by filename.

type HalfBashWriter

type HalfBashWriter struct {
	Writer
	Buffer  *bytes.Buffer
	BlockBB []byte
	BlockWB []byte
	BlockBW []byte
	BlockWW []byte
}

HalfBashWriter implements QR Writer by 'echo' command, output to terminal stdout.

func NewHalfBashWriter

func NewHalfBashWriter(l Level, w io.Writer) *HalfBashWriter

NewHalfBashWriter returns a HalfBashWriter instance after initialization.

func (*HalfBashWriter) Invert

func (w *HalfBashWriter) Invert() *HalfBashWriter

Invert the color of block.

func (*HalfBashWriter) QR

func (w *HalfBashWriter) QR(text string) error

QR encode text at the given error correction level, and write to the given io.Writer.

func (*HalfBashWriter) Write

func (w *HalfBashWriter) Write(p []byte) (err error)

Write the io.Writer wraps the basic Write method.

type HalfBlockWriter

type HalfBlockWriter struct {
	Writer
	BlockBB []byte
	BlockWB []byte
	BlockBW []byte
	BlockWW []byte
}

HalfBlockWriter implements QR Writer use Unicode Block Elements, output to text.

func NewHalfBlockWriter

func NewHalfBlockWriter(l Level, w io.Writer) *HalfBlockWriter

NewHalfBlockWriter returns a HalfBlockWriter instance after initialization.

func (*HalfBlockWriter) Invert

func (w *HalfBlockWriter) Invert() *HalfBlockWriter

Invert the color of block.

func (*HalfBlockWriter) QR

func (w *HalfBlockWriter) QR(text string) error

QR encode text at the given error correction level, and write to the given io.Writer.

func (*HalfBlockWriter) QRFile

func (w *HalfBlockWriter) QRFile(filename, text string) error

QRFile encode text at the given error correction level, and rewrite to a file named by filename.

type Image

type Image struct {
	*qr.Code
	// contains filtered or unexported fields
}

Image implements image.Image

func (*Image) At

func (c *Image) At(x, y int) color.Color

At returns the color of the pixel at (x, y). At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid. At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.

func (*Image) Bounds

func (c *Image) Bounds() image.Rectangle

Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).

func (*Image) ColorModel

func (c *Image) ColorModel() color.Model

ColorModel returns the Image's color model.

type JPEGWriter

type JPEGWriter struct {
	Writer
}

JPEGWriter implements QR Writer for a JPEG image.

func NewJPEGWriter

func NewJPEGWriter(l Level, ws ...io.Writer) *JPEGWriter

NewJPEGWriter returns a JPEGWriter instance after initialization.

func (*JPEGWriter) QR

func (w *JPEGWriter) QR(text string) error

QR encode text at the given error correction level, and write to the given io.Writer.

func (*JPEGWriter) QRFile

func (w *JPEGWriter) QRFile(filename, text string) error

QRFile encode text at the given error correction level, and rewrite to a file named by filename.

type Level

type Level qr.Level

Level denotes a QR error correction level. From least to most tolerant of errors, they are L, M, Q, H.

type PNGWriter

type PNGWriter struct {
	Writer
}

PNGWriter implements QR Writer for a PNG image.

func NewPNGWriter

func NewPNGWriter(l Level, ws ...io.Writer) *PNGWriter

NewPNGWriter returns a PNGWriter instance after initialization.

func (*PNGWriter) QR

func (w *PNGWriter) QR(text string) error

QR encode text at the given error correction level, and write to the given io.Writer.

func (*PNGWriter) QRFile

func (w *PNGWriter) QRFile(filename, text string) error

QRFile encode text at the given error correction level, and rewrite to a file named by filename.

type Writer

type Writer struct {
	Level     Level
	Writer    io.Writer
	QuietZone int
}

Writer denotes a basic QR io.Writer.

func (*Writer) Write

func (w *Writer) Write(p []byte) (err error)

Write the io.Writer wraps the basic Write method.

func (*Writer) WriteFile

func (w *Writer) WriteFile(filename string, data []byte) error

WriteFile writes data to a file named by filename. If the file does not exist, WriteFile creates it with permissions perm; otherwise WriteFile truncates it before writing.

Jump to

Keyboard shortcuts

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