Skip to content

Instantly share code, notes, and snippets.

@AWtnb
Created October 8, 2020 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AWtnb/95c1bb535f7215b7c20e456406525bee to your computer and use it in GitHub Desktop.
Save AWtnb/95c1bb535f7215b7c20e456406525bee to your computer and use it in GitHub Desktop.
qrcode generater with golang
package main
import (
"flag"
"fmt"
"image/png"
"os"
"time"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"
)
func main() {
var (
s string
px int
)
flag.StringVar(&s, "s", "", "string to convert")
flag.IntVar(&px, "px", 400, "size of qrcode")
flag.Parse()
qrCode, _ := qr.Encode(s, qr.M, qr.Auto)
qrCode, _ = barcode.Scale(qrCode, px, px)
fname := fmt.Sprintf("qrcode%v_%v.png", px, time.Now().Format("20060102150405"))
fmt.Printf("converting to QR code '%v':\n'%v'\n", fname, s)
file, _ := os.Create(fname)
defer file.Close()
png.Encode(file, qrCode)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment