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

CLI: Add support to change the encoding (i.e. UTF-8) #84

Closed
PaulKraut opened this issue Aug 30, 2020 · 6 comments
Closed

CLI: Add support to change the encoding (i.e. UTF-8) #84

PaulKraut opened this issue Aug 30, 2020 · 6 comments
Milestone

Comments

@PaulKraut
Copy link

Hi,

Creating a qr-code with "German Umlauts":

$ segno -o=fool.png --encoding="UTF-8" --title="Example QR code" "The Fool on [123-äöüÖÄÜ-456] the Hill"

creates the fool.png file. Showing that png on my desktop and taking a picture smartphone (Galaxy Note 10), the smartphone finds the qr-code immediately, but it the German umlauts have been wrongly translated to some special characters (see Photo).

I use my Smartphone often to read qr-codes with Umlauts. I did not observe utf-8 decoding issues yet. Do you have any idea

Interestingly, fool.png can be decoded by zbarimg correctly as:
$ zbarimg fool.png QR-Code:The Fool on [123-äöüÖÄÜ-456] the Hill

Do you have any idea, why the qr-codes with German Umlauts are wrongly decoded by my smartphone, but correctly with zbarimg? Di you see any possibility for a workarounf or finxing?

Thank you & kind regards,
tempFileForShare_20200830-232619
resized_fool

@heuer
Copy link
Owner

heuer commented Aug 31, 2020

Thanks for your report.

It seems to be a problem with the CLI. The QR code is not encoded with UTF-8 but ISO 8859-1.

The correct output (using UTF-8) would be:
fool-utf-8

segno.make_qr('The Fool on [123-äöüÖÄÜ-456] the Hill', encoding='utf-8') \
     .save('fool-utf-8.png', scale=3)

ZXing and other decoders are able to decode both QR codes correctly, but I'll check why the command line interface ignores the encoding.

@heuer
Copy link
Owner

heuer commented Aug 31, 2020

Ah, I got it! --encoding is used by the SVG serializer and is not used to encode the input. :(

I'm thinking of a solution, thanks for the hint!

@heuer heuer changed the title UTF-8 and German Umlauts CLI: Add support to change the encoding (i.e. UTF-8) Aug 31, 2020
@heuer heuer added this to the 1.2.2 milestone Aug 31, 2020
@PaulKraut
Copy link
Author

Hi,

thanks for the immediate response 👍

Maybe it is worth to mention, that the encoding issue also exist when you use the helpers functions for any qr-code with free text:

I met the problem, when I tried to create a vcard qr-code with helpers.make_vcard() containing an Umlaut: I was not allowed to explicitly specify the encoding, yet.

Probably the best way would be, that the app detects itself, whether or not to fall back into UTF-8 encoding. But I have no clue, what this means for coding ..

Kind regards,

@heuer
Copy link
Owner

heuer commented Aug 31, 2020

I met the problem, when I tried to create a vcard qr-code with helpers.make_vcard() containing an Umlaut: I was not allowed to explicitly specify the encoding, yet.

Well, I think the behaviour (try ISO 8859-1 and if it does not fit, use UTF-8) is correct acc. to ISO/IEC 18004. It seems to be an issue with the decoder app. Which decoder app do you use, btw?

The helpers module provides for each QR code factory function also a _data function which can be used as input for segno.make.

>>> import segno
>>> from segno import helpers
>>> qr = helpers.make_vcard(name='Müller;Änne', displayname='Änne Müller', email='aenne@example.org', phone='+1234567')
>>> qr.save('vcard-iso.png', scale=5)
>>> # Use the _data factory
>>> data = helpers.make_vcard_data(name='Müller;Änne', displayname='Änne Müller', email='aenne@example.org', phone='+1234567')
>>> # Create and save a QR code with an explicit encoding == UTF-8
>>> segno.make(data, encoding='utf-8').save('vcard-utf8.png', scale=5)

Results

ISO 8859-1
vcard-iso

Decoded (using ZXing)
vcard-iso-decoded

UTF-8
vcard-utf8

Decoded:
vcard-utf8-decoded

@PaulKraut
Copy link
Author

Well, I think the behaviour (try ISO 8859-1 and if it does not fit, use UTF-8) is correct acc. to ISO/IEC 18004. It seems to be an issue with the decoder app. Which decoder app do you use, btw?

Ah, now I got it, sorry:

In my first post, was confused why the zbarimg (linux, command line tool) returned the correct string, while the qr-decoder in the smartphone photo-app failed: zbarimg used latin-1 and the Samsung photo-App seems not to be able to handle latin-1.

The helpers module provides for each QR code factory function also a _data function which can be used as input for segno.make.

>>> import segno
>>> from segno import helpers
>>> qr = helpers.make_vcard(name='Müller;Änne', displayname='Änne Müller', email='aenne@example.org', phone='+1234567')
>>> qr.save('vcard-iso.png', scale=5)
>>> # Use the _data factory
>>> data = helpers.make_vcard_data(name='Müller;Änne', displayname='Änne Müller', email='aenne@example.org', phone='+1234567')
>>> # Create and save a QR code with an explicit encoding == UTF-8
>>> segno.make(data, encoding='utf-8').save('vcard-utf8.png', scale=5)

Results

ISO 8859-1
vcard-iso

Decoded (using ZXing)
vcard-iso-decoded

UTF-8
vcard-utf8

Decoded:
vcard-utf8-decoded

Perfect! Helped a lot, thank you very much!

@heuer heuer closed this as completed in d3b9e69 Aug 31, 2020
heuer added a commit that referenced this issue Aug 31, 2020
@heuer
Copy link
Owner

heuer commented Aug 31, 2020

Ah, now I got it, sorry:

In my first post, was confused why the zbarimg (linux, command line tool) returned the correct string, while the qr-decoder in the smartphone photo-app failed: zbarimg used latin-1 and the Samsung photo-App seems not to be able to handle latin-1.

No problem, thank you for discovering a bug! 👍

Your example

$ segno -o=fool.png --encoding="UTF-8" "The Fool on [123-äöüÖÄÜ-456] the Hill"

should work as expected with release 1.3.0

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

No branches or pull requests

2 participants