Created
August 31, 2019 13:23
-
-
Save skip2/0306ffc0553d236af03a600f92cefdeb to your computer and use it in GitHub Desktop.
Demo of generating a QR Code Data URI
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 ( | |
"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