Decoding doesn't work properly
- Dominant language
- Go
- Stars
- 17
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
Hey chai,
Thank you for the great tool! Encoding works fast and well!
However, decoding isn't really working properly.
I would like to encode as much text as possible and encountered issues, as soon as the text is more than 100 characters long.
You can try the following modified `hello.go` with the parameters (tested on Win10, x64):
```go
// Copyright 2014 . All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ingore
// QR codes encoder.
package main
import (
"bytes"
"flag"
"fmt"
"image"
_ "image/jpeg"
_ "image/png"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"github.com/chai2010/qrcode"
)
var (
flagText = flag.String("text", "chaishushan@gmail.com", "Set text")
flagLevel = flag.String("n", "M", "Set QR encode level(L|M|Q|H), default is 'Q'.")
flagOutput = flag.String("o", "qrcode.png", "Set output filename (PNG only).")
)
func init() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] text\n", filepath.Base(os.Args[0]))
flag.PrintDefaults()
}
}
func main() {
flag.Parse()
filename := filepath.Clean(*flagOutput)
if filename == "" {
filename = "qr.png"
}
if !strings.HasSuffix(strings.ToLower(filename), ".png") {
filename += ".png"
}
level := qrcode.Q
switch strings.ToUpper(*flagLevel) {
case "L":
level = qrcode.L
case "M":
level = qrcode.M
case "Q":
level = qrcode.Q
case "H":
level = qrcode.H
}
code, err := qrcode.Encode(*flagText, level)
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile(filename, code.PNG(), 0666)
if err != nil {
log.Fatal(err)
}
fmt.Println("Save as:", filename)
// Load file data
data, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
// Decode image
m, _, err := image.Decode(bytes.NewReader(data))
if err != nil {
log.Fatal(err)
}
// Decode QR Code
text, err := qrcode.Decode(m)
if err != nil {
log.Fatal(err)
}
fmt.Println(filename, ":", text)
}
```
Output
> C:\Users\JamesCullum\go\src\github.com\chai2010\qrcode>go run hello.go -text=uGS8wfili1eOUZfXBFFp8mmVyrOg7xROMF0tljABst6K1h3z5O4Fd3AA -n=L
> Save as: qrcode.png
> qrcode.png : uGS8wfili1eOUZfXBFFp8mmVyrOg7xROMF0tljABst6K1h3z5O4Fd3AA
>
> C:\Users\JamesCullum\go\src\github.com\chai2010\qrcode>go run hello.go -text=uGS8wfili1eOUZfXBFFp8mmVyrOg7xROMF0tljABst6K1h3z5O4Fd3AA1xBDsVGhHl2J2GGM5Xf1Br1tHRHpsVSvSxYehyF1EAZGloDxCQNgnv7omEkkPvC1Z8xZPCjob7YnHSclHQnOpVYo0PIS5z -n=L
> Save as: qrcode.png
> qrcode.png : uGS8wfili1eOUZfXBFL�`�ʼ����n𤞊�p��Ԓ���l�r�v�j�x��v��b���漞���t�d���z��r�r1tHRHpsVSvSxYehyF2�����Θ�������~�ʊ�֠��b�pഠ����n�̀���̎༲�`���j�
In each case for more than 100 characters, the characters get encoded weirdly and are incorrect. For characters longer or higher error correction, the script crashes.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.