Home

Awesome

go-qr

Mentioned in Awesome Go Go Report Card Build Status Codecov GoDoc License: MIT

🎶 Go Community Minimalist QR Code Generator Library.

Overview

This library is native, high quality and minimalistic. Generate QR code from string text

It is mostly a translation of project Nayuki's Java version of the QR code generator.

Features

Installation

go get github.com/piglig/go-qr

Examples

package main

import (
	go_qr "github.com/piglig/go-qr"
	"image/color"
)

func main() {
	doBasicDemo()
}

func doBasicDemo() {
	text := "Hello, world!"
	errCorLvl := go_qr.Low
	qr, err := go_qr.EncodeText(text, errCorLvl)
	if err != nil {
		return
	}
	config := go_qr.NewQrCodeImgConfig(10, 4)
	err = qr.PNG(config, "hello-world-QR.png")
	if err != nil {
		return
	}

	err = qr.SVG(config, "hello-world-QR.svg", "#FFFFFF", "#000000")
	if err != nil {
		return
	}
}

Command Line Tool

generator command line tool to generate the QR Code.

Installation

In order to use the tool, compile it using the following command

go install github.com/piglig/go-qr/tools/generator@latest

Usage

generator [options] [arguments]
  -content string
        Content to encode in the QR code
  -png string
        Output PNG file name
  -svg string
        Output SVG file name
  -svg-optimized
        Output optimized SVG file name - regions with connected black pixels are merged into a single path

Example

generator -content hello

Gif

generator -content hello -png hello.png -svg hello.svg

Gif

generator -content hello -svg hello.svg -svg-optimized hello-optimized.svg 

The optimized svg output create paths around connected black regions. This reduces the file size and rendering artifacts. svg

License

See the LICENSE file for license rights and limitations (MIT).