Created
October 8, 2020 08:32
-
-
Save AWtnb/95c1bb535f7215b7c20e456406525bee to your computer and use it in GitHub Desktop.
qrcode generater with golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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