2025-01-26 00:48:19 +00:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
2025-04-29 23:25:32 +01:00
|
|
|
"encoding/base64"
|
|
|
|
"image"
|
|
|
|
"image/color"
|
2025-01-26 20:09:18 +00:00
|
|
|
|
|
|
|
"github.com/skip2/go-qrcode"
|
2025-01-26 00:48:19 +00:00
|
|
|
)
|
|
|
|
|
2025-01-26 20:09:18 +00:00
|
|
|
func GenerateQRCode(data string) (string, error) {
|
|
|
|
imgBytes, err := qrcode.Encode(data, qrcode.Medium, 256)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
base64Img := base64.StdEncoding.EncodeToString(imgBytes)
|
|
|
|
return base64Img, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// vvv DEPRECATED vvv
|
|
|
|
|
2025-01-26 00:48:19 +00:00
|
|
|
const margin = 4
|
|
|
|
|
|
|
|
type QRCodeECCLevel int64
|
|
|
|
const (
|
|
|
|
LOW QRCodeECCLevel = iota
|
|
|
|
MEDIUM
|
|
|
|
QUARTILE
|
|
|
|
HIGH
|
|
|
|
)
|
|
|
|
|
|
|
|
func drawLargeAlignmentSquare(x int, y int, img *image.Gray) {
|
|
|
|
for yi := range 7 {
|
|
|
|
for xi := range 7 {
|
|
|
|
if (xi == 0 || xi == 6) || (yi == 0 || yi == 6) {
|
|
|
|
img.Set(x + xi, y + yi, color.Black)
|
|
|
|
} else if (xi > 1 && xi < 5) && (yi > 1 && yi < 5) {
|
|
|
|
img.Set(x + xi, y + yi, color.Black)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func drawSmallAlignmentSquare(x int, y int, img *image.Gray) {
|
|
|
|
for yi := range 5 {
|
|
|
|
for xi := range 5 {
|
|
|
|
if (xi == 0 || xi == 4) || (yi == 0 || yi == 4) {
|
|
|
|
img.Set(x + xi, y + yi, color.Black)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
img.Set(x + 2, y + 2, color.Black)
|
|
|
|
}
|