encode the barcode as base64
hafizarr opened this issue · comments
Hi, can I encode the barcode as base64, without save file img? thanks :)
package main
import (
"bytes"
"encoding/base64"
"fmt"
"image/png"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"
)
func main() {
// Create the barcode
qrCode, _ := qr.Encode("Hello World", qr.M, qr.Auto)
// Scale the barcode to 200x200 pixels
qrCode, _ = barcode.Scale(qrCode, 200, 200)
// create the output buffer
buf := new(bytes.Buffer)
// encode the barcode as png
png.Encode(buf, qrCode)
s := base64.StdEncoding.EncodeToString(buf.Bytes())
fmt.Println(s)
}
like this?