README.md (3292B)
1 # go-qrcode # 2 3 <img src='https://skip.org/img/nyancat-youtube-qr.png' align='right'> 4 5 Package qrcode implements a QR Code encoder. [](https://travis-ci.org/skip2/go-qrcode) 6 7 A QR Code is a matrix (two-dimensional) barcode. Arbitrary content may be encoded, with URLs being a popular choice :) 8 9 Each QR Code contains error recovery information to aid reading damaged or obscured codes. There are four levels of error recovery: Low, medium, high and highest. QR Codes with a higher recovery level are more robust to damage, at the cost of being physically larger. 10 11 ## Install 12 13 go get -u github.com/skip2/go-qrcode/... 14 15 A command-line tool `qrcode` will be built into `$GOPATH/bin/`. 16 17 ## Usage 18 19 import qrcode "github.com/skip2/go-qrcode" 20 21 - **Create a 256x256 PNG image:** 22 23 var png []byte 24 png, err := qrcode.Encode("https://example.org", qrcode.Medium, 256) 25 26 - **Create a 256x256 PNG image and write to a file:** 27 28 err := qrcode.WriteFile("https://example.org", qrcode.Medium, 256, "qr.png") 29 30 - **Create a 256x256 PNG image with custom colors and write to file:** 31 32 err := qrcode.WriteColorFile("https://example.org", qrcode.Medium, 256, color.Black, color.White, "qr.png") 33 34 All examples use the qrcode.Medium error Recovery Level and create a fixed 256x256px size QR Code. The last function creates a white on black instead of black on white QR Code. 35 36 ## Documentation 37 38 [](https://godoc.org/github.com/skip2/go-qrcode) 39 40 ## Demoapp 41 42 [http://go-qrcode.appspot.com](http://go-qrcode.appspot.com) 43 44 ## CLI 45 46 A command-line tool `qrcode` will be built into `$GOPATH/bin/`. 47 48 ``` 49 qrcode -- QR Code encoder in Go 50 https://github.com/skip2/go-qrcode 51 52 Flags: 53 -d disable QR Code border 54 -i invert black and white 55 -o string 56 out PNG file prefix, empty for stdout 57 -s int 58 image size (pixel) (default 256) 59 -t print as text-art on stdout 60 61 Usage: 62 1. Arguments except for flags are joined by " " and used to generate QR code. 63 Default output is STDOUT, pipe to imagemagick command "display" to display 64 on any X server. 65 66 qrcode hello word | display 67 68 2. Save to file if "display" not available: 69 70 qrcode "homepage: https://github.com/skip2/go-qrcode" > out.png 71 72 ``` 73 ## Maximum capacity 74 The maximum capacity of a QR Code varies according to the content encoded and the error recovery level. The maximum capacity is 2,953 bytes, 4,296 alphanumeric characters, 7,089 numeric digits, or a combination of these. 75 76 ## Borderless QR Codes 77 78 To aid QR Code reading software, QR codes have a built in whitespace border. 79 80 If you know what you're doing, and don't want a border, see https://gist.github.com/skip2/7e3d8a82f5317df9be437f8ec8ec0b7d for how to do it. It's still recommended you include a border manually. 81 82 ## Links 83 84 - [http://en.wikipedia.org/wiki/QR_code](http://en.wikipedia.org/wiki/QR_code) 85 - [ISO/IEC 18004:2006](http://www.iso.org/iso/catalogue_detail.htm?csnumber=43655) - Main QR Code specification (approx CHF 198,00)<br> 86 - [https://github.com/qpliu/qrencode-go/](https://github.com/qpliu/qrencode-go/) - alternative Go QR encoding library based on [ZXing](https://github.com/zxing/zxing)