在控制台中生成二维码的简单方法是什么 [英] What is an easy way to generate a QR-Code in a console

查看:50
本文介绍了在控制台中生成二维码的简单方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用例如下:我想在 Gajim Windows 中显示我的 OMEMO-Fingerprint 以验证它,但无法让它在那里工作.所以我正在寻找一种从控制台生成特定二维码的简单方法.这样做,应该(我期望)像 xmpp-URI 格式一样简单,这很容易.

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.

推荐答案

我发现使用 Pythonpython3-qrcode 可以这样管理:

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

安装 Python 和所需的模块:

Install Python and the needed modules:

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

使用此在线批处理或 bash 文件 - 它不仅适用于 Windows,还适用于 Linux 等:

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

第一个输入(你当然可以替换%1)应该转换成二维码的string,例如xmpp:user@example.de?omemo-sid-123456789=cf4d1558a8b872e6d8d213be2d3ac447663b3d516509f56536d80b70ca0e8e89%2 目标文件result.png.基本上就是这样.

It takes as the first input (you can replace %1 of course) the string that should be converted to QR, for example xmpp:user@example.de?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

这篇关于在控制台中生成二维码的简单方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆