qrcode

package module
v0.0.0-...-1335e20 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: MIT Imports: 9 Imported by: 0

README

qrcode

This pacakge can simple QR code encoding. It only supoprts version 1, so very short string can only be encoded.

How to use

install package

go get github.com/ksrnnb/qrcode

Example

package main

import (
	"fmt"
	"os"

	"github.com/ksrnnb/qrcode"
)

func main() {
	q, err := qrcode.New(qrcode.ECL_Medium, "Hello, World")
	if err != nil {
		fmt.Fprintf(os.Stderr, "cannot be encoded: %v\n", err)
		return
	}

	size := 255
	p, err := q.PNG(size)
	if err != nil {
		fmt.Fprintf(os.Stderr, "png encode error: %v\n", err)
		return
	}

	err = os.WriteFile("qrcode.png", p, 0666)
	if err != nil {
		fmt.Fprintf(os.Stderr, "write file error: %v\n", err)
		return
	}
}

Reference

Japanese Reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatInfo

func FormatInfo(ecl ErrorCorrectionLevel, mask uint8) *bitset.BitSet

Types

type ErrorCorrectionLevel

type ErrorCorrectionLevel uint8
const (
	// Level L
	ECL_Low ErrorCorrectionLevel = 0b01

	// Level M
	ECL_Medium ErrorCorrectionLevel = 0b00

	// Level Q
	ECL_High ErrorCorrectionLevel = 0b11

	// Level H
	ECL_Highest ErrorCorrectionLevel = 0b10
)

type ModeIndicator

type ModeIndicator uint8
const (
	Numeric ModeIndicator = 1 << iota

	AlphaNumeric

	// 8 bits byte
	EightBits

	Kanji
)

reference: JIS X0510 : 2018 (ISO/IEC 18004 : 2015) Table 2

type QRCode

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

func New

func New(ecl ErrorCorrectionLevel, content string) (*QRCode, error)

func (*QRCode) Image

func (q *QRCode) Image(size int) image.Image

func (*QRCode) PNG

func (q *QRCode) PNG(size int) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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