heuer / segno

Python QR Code and Micro QR Code encoder
https://pypi.org/project/segno/
BSD 3-Clause "New" or "Revised" License
606 stars 52 forks source link

Unable to create QR codes with modes less than binary/'bytes' #122

Closed cjtenny closed 1 year ago

cjtenny commented 1 year ago

I think https://github.com/heuer/segno/blob/master/segno/encoder.py#L1040 will cause https://github.com/heuer/segno/blob/master/segno/encoder.py#L1049 to always fail for numeric, alphanumeric, and structured append modes. Specifically, I'm trying to create an alphanumeric microQR code in mode M2 with the following line:

segno.make_micro("text", version="M2", mode="alphanumeric")

And I don't think Segno will allow me to do it with any data - but I'm pretty tired right now. Maybe I'm missing something?

cjtenny commented 1 year ago

Oops - turns out the alphanumeric mode is only selectable with uppercase characters, there's no case-folding. My thoughts about the code-path were wrong. Closing, sorry!

heuer commented 1 year ago

Glad you found it out yourself. In alphanumeric mode the following characters are allowed: ABCDEFGHIJKLMNOPQRSTUVWXYZ$%*+-./:, and space .

If the version does not matter, you can omit the mode and version information and Segno creates an optimal, minimal Micro QR Code for the provided input:

>>> qr = segno.make_micro("text")
>>> qr.designator
'M3-M'

The Structured Append mode is not supported by Micro QR Codes, only by QR Codes.