• Stars
    star
    117
  • Rank 301,828 (Top 6 %)
  • Language
    Go
  • License
    GNU Lesser Genera...
  • Created over 12 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

QR encoder in Go

QR encoder in Go based on the ZXing encoder (http://code.google.com/p/zxing/).

GoDoc Build Status

I was surprised that I couldn't find a QR encoder in Go, especially since the example at http://golang.org/doc/effective_go.html#web_server is a QR code generator, though the QR encoding is done by an external Google service in the example.

Example

package main

import (
	"bytes"
	"image/png"
	"os"

	"github.com/qpliu/qrencode-go/qrencode"
)

func main() {
	var buf bytes.Buffer
	for i, arg := range os.Args {
		if i > 1 {
			if err := buf.WriteByte(' '); err != nil {
				panic(err)
			}
		}
		if i > 0 {
			if _, err := buf.WriteString(arg); err != nil {
				panic(err)
			}
		}
	}
	grid, err := qrencode.Encode(buf.String(), qrencode.ECLevelQ)
	if err != nil {
		panic(err)
	}
	png.Encode(os.Stdout, grid.Image(8))
}