Barcode generation with Boombuler
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package qrcode
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image/png"
|
||||
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/qr"
|
||||
)
|
||||
|
||||
func GeneratePNG(content string, size int) ([]byte, error) {
|
||||
if size <= 0 {
|
||||
size = 256
|
||||
}
|
||||
|
||||
qrCode, err := qr.Encode(content, qr.M, qr.Auto)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
qrCode, err = barcode.Scale(qrCode, size, size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
if err := png.Encode(&buf, qrCode); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
Reference in New Issue
Block a user