-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (47 loc) · 1.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"log"
"os"
"bufio"
"strings"
qrcode "github.com/skip2/go-qrcode"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter the text to generate QR code: ")
input, err := reader.ReadString('\n')
if err != nil {
log.Fatalf("Error reading input: %v", err)
}
input = strings.TrimSpace(input)
fmt.Print("Enter the output file name (e.g., my_massage): ")
outputFile, err := reader.ReadString('\n')
if err != nil {
log.Fatalf("Error reading output file name: %v", err)
}
outputFile = strings.TrimSpace(outputFile)
outputFile = outputFile + ".png"
err = generateQRCode(input, outputFile)
if err != nil {
log.Fatalf("Error generating QR code: %v", err)
}
fmt.Println("QR code generated successfully!")
}
func generateQRCode(text, outputFile string) error {
err := qrcode.WriteFile(text, qrcode.Medium, 256, outputFile)
if err != nil {
return err
}
file, err := os.Open("qr.png")
if err != nil {
return err
}
defer file.Close()
fileInfo, err := file.Stat()
if err != nil {
return err
}
fmt.Printf("QR code image size: %d bytes\n", fileInfo.Size())
return nil
}