Home

Awesome

go-qrcode

Go Report Card go.dev reference Go GitHub release (latest SemVer) GitHub go.mod Go version License

<img src="./assets/repository_qrcode.png" width="100px" align="right"/> QR code (abbreviated from Quick Response Code) is the trademark for a type of matrix barcode (or two-dimensional barcode) first designed in 1994 for the automotive industry in Japan. A barcode is a machine-readable optical label that contains information about the item to which it is attached. A QR code uses four standardized encoding modes (numeric, alphanumeric, byte/binary, and kanji) to store data efficiently; extensions may also be used

Features

Install

go get -u github.com/yeqown/go-qrcode/v2

Quick Start

link to CODE

package main

import (
	"github.com/yeqown/go-qrcode/v2"
	"github.com/yeqown/go-qrcode/writer/standard"
)

func main() {
	qrc, err := qrcode.New("https://github.com/yeqown/go-qrcode")
	if err != nil {
		fmt.Printf("could not generate QRCode: %v", err)
		return
	}
	
	w, err := standard.New("../assets/repo-qrcode.jpeg")
	if err != nil {
		fmt.Printf("standard.New failed: %v", err)
		return
	}
	
	// save file
	if err = qrc.Save(w); err != nil {
		fmt.Printf("could not save image: %v", err)
	}
}

Options

const (
	// EncModeNone mode ...
	EncModeNone encMode = 1 << iota
	// EncModeNumeric mode ...
	EncModeNumeric
	// EncModeAlphanumeric mode ...
	EncModeAlphanumeric
	// EncModeByte mode ...
	EncModeByte
	// EncModeJP mode ...
	EncModeJP
)

// WithEncodingMode sets the encoding mode.
func WithEncodingMode(mode encMode) EncodeOption {}

const (
	// ErrorCorrectionLow :Level L: 7% error recovery.
	ErrorCorrectionLow ecLevel = iota + 1
	
	// ErrorCorrectionMedium :Level M: 15% error recovery. Good default choice.
	ErrorCorrectionMedium
	
	// ErrorCorrectionQuart :Level Q: 25% error recovery.
	ErrorCorrectionQuart
	
	// ErrorCorrectionHighest :Level H: 30% error recovery.
	ErrorCorrectionHighest
)

// WithErrorCorrectionLevel sets the error correction level.
func WithErrorCorrectionLevel(ecLevel ecLevel) EncodeOption {}

following are some shots:

<div> <img src="./assets/example_fg_bg.jpeg" width="160px" align="left" title="with bg-fg color"> <img src="./assets/example_logo.jpeg" width="160px" align="left" title="with logo image"> <img src="./assets/example_circle.jpeg" width="160px" align="left" title="customize block shape"> <img src="./assets/example_transparent.png" width="160px" title="with transparent bg"> </div> <div> <img src="./assets/example_halftone0.jpeg" width="160px" align="left" title="halftone0"> <img src="./assets/example_halftone1.jpeg" width="160px" align="left" title="halftone1"> <img src="./assets/example_halftone2.png" width="160px" align="left" title="halftone2"> <img src="./assets/example_halftone3.jpeg" width="160px" title="halftone3"> </div> <br>

Built-in Writers

Of course, you can also code your own writer, just implement Writer interface.

Migrating from v1

go-qrcode.v2 is a major upgrade from v1, and it is not backward compatible. v2 redesigned the API, and it is more flexible and powerful. Features are split into different modules (according to functionality).

Check example/migrating-from-v1 for more details.

Links