🎶 Go Community Minimalist QR Code Generator Library.
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.
- Minimalist native code implementation
- Based on QR Code Model 2 standard, supports all 40 versions and all 4 error correction levels
- Output format: Raw modules/pixels of the QR symbol
- Detects finder-like penalty patterns more accurately than other implementations
- Encoding space optimisation for numeric and special alphanumeric texts
- Japanese Unicode Text Encoding Optimisation
- For mixed numeric/alphanumeric/general/kanji text, computes optimal segment mode switching
- Good test coverage
- MIT's Open Source License
go get github.com/piglig/go-qr
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
}
err = qr.SVG(go_qr.NewQrCodeImgConfig(10, 4, go_qr.WithSVGXMLHeader(true)), "hello-world-QR-xml-header.svg", "#FFFFFF", "#000000")
if err != nil {
return
}
}
generator command line tool to generate the QR Code.
In order to use the tool, compile it using the following command
go install github.com/piglig/go-qr/tools/generator@latest
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
- Text Art
generator -content hello
- Image Type
generator -content hello -png hello.png -svg hello.svg
- Optimized SVG Type
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.
See the LICENSE file for license rights and limitations (MIT).