parent
e5d7dc4bbb
commit
d69ed587eb
@ -1,3 +1,4 @@ |
||||
rnd-english |
||||
*.txt |
||||
*.db |
||||
*.png |
||||
|
||||
@ -0,0 +1,49 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"image" |
||||
_ "image/png" // Required to decode PNG files
|
||||
"log" |
||||
"flag" |
||||
"os" |
||||
|
||||
"github.com/makiuchi-d/gozxing" |
||||
"github.com/makiuchi-d/gozxing/qrcode" |
||||
) |
||||
|
||||
func main() { |
||||
input := flag.String("input", "qrcode.png", "Input filename for QR code") |
||||
flag.Parse() |
||||
|
||||
// Open the PNG file
|
||||
file, err := os.Open(*input) |
||||
if err != nil { |
||||
log.Fatal(err) |
||||
} |
||||
defer file.Close() |
||||
|
||||
// Decode the image
|
||||
img, _, err := image.Decode(file) |
||||
if err != nil { |
||||
log.Fatal(err) |
||||
} |
||||
|
||||
// Convert image to BinaryBitmap
|
||||
bmp, err := gozxing.NewBinaryBitmapFromImage(img) |
||||
if err != nil { |
||||
log.Fatal(err) |
||||
} |
||||
|
||||
// Prepare a QR code reader
|
||||
reader := qrcode.NewQRCodeReader() |
||||
|
||||
// Decode the QR code
|
||||
result, err := reader.Decode(bmp, nil) |
||||
if err != nil { |
||||
log.Fatal(err) |
||||
} |
||||
|
||||
// Print the decoded content
|
||||
fmt.Println("Decoded QR code:", result.GetText()) |
||||
} |
||||
@ -1,4 +1,10 @@ |
||||
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI= |
||||
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= |
||||
github.com/makiuchi-d/gozxing v0.1.1 h1:xxqijhoedi+/lZlhINteGbywIrewVdVv2wl9r5O9S1I= |
||||
github.com/makiuchi-d/gozxing v0.1.1/go.mod h1:eRIHbOjX7QWxLIDJoQuMLhuXg9LAuw6znsUtRkNw9DU= |
||||
github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A= |
||||
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= |
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= |
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= |
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= |
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= |
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= |
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
||||
|
||||
@ -0,0 +1,25 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"flag" |
||||
"log" |
||||
"github.com/skip2/go-qrcode" |
||||
) |
||||
|
||||
func main() { |
||||
// Define flags
|
||||
data := flag.String("data", "", "Data to encode in QR code") |
||||
output := flag.String("output", "qrcode.png", "Output filename for QR code") |
||||
flag.Parse() |
||||
|
||||
// Validate required flag
|
||||
if *data == "" { |
||||
log.Fatal("Data is required. Usage: -data <text> [-output <filename>]") |
||||
} |
||||
|
||||
err := qrcode.WriteFile(*data, qrcode.Highest, 512, *output) |
||||
if err != nil { |
||||
log.Fatal(err) |
||||
} |
||||
log.Printf("QR code with data '%s' saved as %s\n", *data, *output) |
||||
} |
||||
Loading…
Reference in new issue