What is an easy way to generate a QR-Code in a console

Issue

My use case is the following: I wanted to show my OMEMO-Fingerprint in Gajim in Windows to verify it, but wasn’t able to get it to work there. So I was looking for an easy way to generate a specific QR-Code from console. Doing that, should (I expect) be as easy as the xmpp-URI-format, which is pretty easy.

Solution

I found that with Python and python3-qrcode, this is manageable like this:

Install Python and the needed modules:

pip install --upgrade pip
pip install cryptography cryptography pillow qrcode setuptools axolotl  

Use this onliner batch or bash file – it works not only in windows but also in Linux and more:

python -c "import qrcode; import sys; qrcode.make(sys.argv[1]).save(sys.argv[2])" %1 %2

It takes as the first input (you can replace %1 of course) the string that should be converted to QR, for example xmpp:[email protected]?omemo-sid-123456789=cf4d1558a8b872e6d8d213be2d3ac447663b3d516509f56536d80b70ca0e8e89 and as %2 the destination file as e.g. result.png. That’s basically it.

If you want to generate a QR-Code out of the content of a file, you can use this:

python -c "import qrcode; import sys; qrcode.make(open(sys.argv[1], 'r').read()).save(sys.argv[2])" %1 %2

Answered By – Cadoiz

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published