Files
huangguo_server/common/qrcode.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

31 lines
538 B
Go

package common
import (
"image"
_ "image/jpeg"
_ "image/png"
"io"
"github.com/makiuchi-d/gozxing"
"github.com/makiuchi-d/gozxing/qrcode"
)
func DecodeQRCode(file io.Reader) (content string, err error) {
img, _, err := image.Decode(file)
if err != nil {
return
}
// prepare BinaryBitmap
bmp, err := gozxing.NewBinaryBitmapFromImage(img)
if err != nil {
return
}
// decode image
qrReader := qrcode.NewQRCodeReader()
result, err := qrReader.Decode(bmp, nil)
if err != nil {
return
}
return result.String(), nil
}