qrascii

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: MIT Imports: 3 Imported by: 1

README

QRAscii

A library to convert QRCode image to ASCII-art, it is useful when you want to display a QRCode in terminal.

Things this lib can NOT do:

  • Generate QRCode from raw data.
  • Get raw data from QRCode.

Usage


import (
    "github.com/deadblue/qrascii"
    "log"
    "os"

    // You need load image decoders by yourself
    _ "image/png"
)

func main() {
    qrFile := "/path/to/qrcode.png"
    f, err := os.Open(qrFile)
	if err != nil {
		log.Fatalf("Load QRCode image failed: %s", err)
	}
	defer f.Close()
	if qr, err := Parse(f); err != nil {
		log.Fatalf("Parse QRCode image failed: %s", err)
	} else {
		print(qr.String())
	}
}

Then you will see the ASCII-art of the QRCode, like this:

█████████████████████████████████
██ ▄▄▄▄▄ ██▀  ███▄▄█▄▄ █ ▄▄▄▄▄ ██
██ █   █ █ █▀▀▀█▄█▄▀▄███ █   █ ██
██ █▄▄▄█ █ █ ▀▀   ▀▀ ▄ █ █▄▄▄█ ██
██▄▄▄▄▄▄▄█ █▄▀▄▀▄▀▄█ █ █▄▄▄▄▄▄▄██
██ █    ▄▀▀▀▀▄██▄█▀ ▀▀▀█   ▄▄█▀██
██▀▄ ▀▀▀▄▀██▄▄ █▀ ▄█▀█▀███▄▀█▀███
███ ▀ ▄▄▄██▀▀▄▄▀▀█▀▄█▀▀▀▀▀▀▄▄█▀██
██▀█ █▄ ▄██▀▀█  ▄▄▄██▀  ▀▀ ▄▄▀███
██▀ ▄ ▄▀▄▀█▄▀▀ █▄▄▀▄▀ █ ▀ ▀▄ █▀██
██ █ █▄▀▄▄▄  ▀▀█▀▄▄███ ▀ ▄▄█▄▀███
██▄█████▄█ ▀▄▄█▀▀▄   ▄ ▄▄▄ ▀   ██
██ ▄▄▄▄▄ █▀███  ▄ ▄▄█  █▄█ ▄▄█▀██
██ █   █ █ █▀▀▄▀▄▄▀▄█▀ ▄▄▄▄▀  ▀██
██ █▄▄▄█ █▄▄▀██▀█▄██▄▄  ▄ ▄ ▄ ███
██▄▄▄▄▄▄▄█▄▄██▄█▄▄▄▄█▄██▄▄▄█▄████
█████████████████████████████████

License

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidQrcode = errors.New("invalid qrcode")
)

Functions

This section is empty.

Types

type Options

type Options struct {
	// Margin size around the QRCode.
	Margin int
	// Invert colors of the QRCode.
	Invert bool
}

Options is used to customize the ASCII-art.

type QRCode

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

QRCode holds the dot map of a QRCode.

func Parse

func Parse(r io.Reader) (q *QRCode, err error)

Parse parses QRCode image from an io.Reader.

Example
qrFile := "/path/to/qrcode.png"
f, err := os.Open(qrFile)
if err != nil {
	log.Fatalf("Load QRCode image failed: %s", err)
}
defer f.Close()
if qr, err := Parse(f); err != nil {
	log.Fatalf("Parse QRCode image failed: %s", err)
} else {
	print(qr.String())
}
Output:

func ParseImage

func ParseImage(im image.Image) (q *QRCode, err error)

ParseImage parses QRCode image.

func (*QRCode) String

func (q *QRCode) String() string

Generate ascii-art with default options

func (*QRCode) ToAscii

func (q *QRCode) ToAscii(opts Options) string

ToAscii converts dot map to ascii art with options.

Jump to

Keyboard shortcuts

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