Barcode generation with Boombuler

This commit is contained in:
2026-05-09 01:01:25 +07:00
parent 4cc563f6f1
commit 07b186c986
8 changed files with 98 additions and 2 deletions
+32
View File
@@ -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
}