Skip to content

Instantly share code, notes, and snippets.

@skip2
Created August 31, 2019 13:23
Show Gist options
  • Save skip2/0306ffc0553d236af03a600f92cefdeb to your computer and use it in GitHub Desktop.
Save skip2/0306ffc0553d236af03a600f92cefdeb to your computer and use it in GitHub Desktop.
Demo of generating a QR Code Data URI
package main
import (
"encoding/base64"
"fmt"
qrcode "github.com/skip2/go-qrcode"
)
func main() {
png, err := qrcode.Encode("https://example.org", qrcode.Medium, 256)
if err != nil {
panic(err)
}
dataURI := "data:image/png;base64," + base64.StdEncoding.EncodeToString([]byte(png))
fmt.Printf("<html><body><h1>qr code:</h1><img src='%s'></body></html>", dataURI)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment