Skip to content

qpliu/qrencode-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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))
}