文章目录
安装qrencode(附官方手册)
# 官方文档
https://fukuchi.org/works/qrencode/index.html.en
https://formulae.brew.sh/formula/qrencode (内含 api文档)
# rhel7系列(base源中)
yum install qrencode -y
# debian系列
apt install qrencode -y
# openwrt系列
opkg update ; opkg install qrencode
工具参数介绍
-o filename.png # 输出到文件(格式为png)
-s
-l [L|M|Q|H] # 指定从L(最低)到H(最高)的纠错级别
-m 4 # 指定二维码的边框(即边距)宽带,默认为4,建议指定为1
-d 72 # 指定生成二维码图片的dpi,默认是72
-t [PNG|EPS|SVG|ANSI] # 指定生成的图像格式,默认为PNG,可选有 PNG、EPS、SVG、ANSI、ANSI256、ASCII、ASCIIi、UTF8、ANSIUTF8 (shell终端建议使用 ANSI、ANSI256、)
附:若是你想生成彩色的二维码,可以配置lolcat工具
典型使用案例
# 看看 ANSI ANSI256 ASCII ASCIIi UTF8 ANSIUTF8 这几种类型的二维码在shell终端的展示情况
for type in ANSI ANSI256 ASCII ASCIIi UTF8 ANSIUTF8;do echo $type ;qrencode -t $type "a";done
# 直接显示在终端(不推荐使用UTF8格式,你用你就知道什么像样儿了)
echo "你好" | qrencode -t ansi256
# qrencode -t ansi256 "你好"
echo "你好" | qrencode -t ansi256 > device_code # 将生成的二维码直接重定向到文件device_code,便于cat读取
# 推荐使用
qrencode -m 2 -t ansiutf8 "$str"
# 生成png图片
qrencode -o qrcode.png "你好"
如果文章对你有帮助,欢迎点击上方按钮打赏作者
暂无评论