Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version Selection is wrong for certain string length #164

Closed
LXMK opened this issue Jan 2, 2019 · 7 comments
Closed

Version Selection is wrong for certain string length #164

LXMK opened this issue Jan 2, 2019 · 7 comments

Comments

@LXMK
Copy link

LXMK commented Jan 2, 2019

Hi, I've noticed that the version is sometimes not selected correctly, depending on length of the string.
ABCDEFGHIJKLMNO1 -> Version 1 (21x21)
ABCDEFGHIJKLMNO12 -> Version1 (21x21)
ABCDEFGHIJKLMNO123 -> Version2 (25x25)
ABCDEFGHIJKLMNO1234 -> Version2 (25x25)
ABCDEFGHIJKLMNO12345 -> Version1 (21x21)
ABCDEFGHIJKLMNO123456 -> Version1 (21x21)

Forcing to Level 1 (fit=False) gives the error:
qrcode.exceptions.DataOverflowError: Code length overflow. Data size (156) > size available (152)

@LXMK
Copy link
Author

LXMK commented Jan 2, 2019

qr-codes

@LXMK
Copy link
Author

LXMK commented Jan 2, 2019

qr = qrcode.QRCode(version=1,
                           error_correction=qrcode.constants.ERROR_CORRECT_L,
                           box_size=20,
                           border=2)
        qr.add_data(self.text)
        qr.make(fit=False)
        img = qr.make_image()

@SmileyChris
Copy link
Member

It isn't just the length of the string taken into account, but the contents. Digits can be encoded more succinctly, so when 4 in a row are found, we switch encoding for that block meaning those extra numbers can use less space than encoded as alphanumeric

@LXMK
Copy link
Author

LXMK commented Jan 7, 2019

It has nothing to do with digits! I've just used them for illustrating. It is the same when only letters are used!

@LXMK
Copy link
Author

LXMK commented Jan 7, 2019

ABCDEFGHIJKLMNOPQRSTU -> Version 1 (21x21)
ABCDEFGHIJKLMNOPQRST -> Version 1 (21x21)
ABCDEFGHIJKLMNOPQRS -> Version2 (25x25)
ABCDEFGHIJKLMNOPQR -> Version2 (25x25)
ABCDEFGHIJKLMNOPQ -> Version 1 (21x21)
ABCDEFGHIJKLMNOP -> Version 1 (21x21)
ABCDEFGHIJKLMNO1 -> Version 1 (21x21)
ABCDEFGHIJKLMNO12 -> Version1 (21x21)
ABCDEFGHIJKLMNO123 -> Version2 (25x25)
ABCDEFGHIJKLMNO1234 -> Version2 (25x25)
ABCDEFGHIJKLMNO12345 -> Version1 (21x21)
ABCDEFGHIJKLMNO123456 -> Version1 (21x21)

@LXMK
Copy link
Author

LXMK commented Jan 7, 2019

qr-codes-allgemein

@SmileyChris
Copy link
Member

It was still an issue with mode encoding, the case was just a bit different.
add_data() optimizes the chunks of data into the correct mode type, but if the data was shorter than the minimum optimization length, it wasn't attempting to pick the correct mode type -- now it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants