Shell中显示彩色二维码

Show

突发奇想,能不能在linux中以文本格式展示二维码呢,这样就可以不借助图片软件直接在我的shell脚本中展示了。虽让现在不知道有啥用,但是配合lolcat装装逼也是不错的。一番google后找到了qrencode,废话不多说,先展示效果。
在这里插入图片描述
没错,这个二维码即是本篇文章的链接

使用

qrencode将输入的数据转化成一个二维码并可以输出成图片和文本的格式。其使用极其简单,将想要转化的数据(支持字符串和网页链接)直接接到其后,指定输出格式(PNG,EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8)即可。
全部参数如下:

[Neptuneyut]$ qrencode
qrencode version 3.4.1
Copyright (C) 2006-2012 Kentaro Fukuchi
Usage: qrencode [OPTION]... [STRING]
Encode input data in a QR Code and save as a PNG or EPS image.

  -h           display this message.
  --help       display the usage of long options.
  -o FILENAME  write image to FILENAME. If '-' is specified, the result
               will be output to standard output. If -S is given, structured
               symbols are written to FILENAME-01.png, FILENAME-02.png, ...
               (suffix is removed from FILENAME, if specified)
  -s NUMBER    specify module size in dots (pixels). (default=3)
  -l {LMQH}    specify error correction level from L (lowest) to H (highest).
               (default=L)
  -v NUMBER    specify the version of the symbol. (default=auto)
  -m NUMBER    specify the width of the margins. (default=4 (2 for Micro))
  -d NUMBER    specify the DPI of the generated PNG. (default=72)
  -t {PNG,EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}
               specify the type of the generated image. (default=PNG)
  -S           make structured symbols. Version must be specified.
  -k           assume that the input text contains kanji (shift-jis).
  -c           encode lower-case alphabet characters in 8-bit mode. (default)
  -i           ignore case distinctions and use only upper-case characters.
  -8           encode entire data in 8-bit mode. -k, -c and -i will be ignored.
  -M           encode in a Micro QR Code.
  --foreground=RRGGBB[AA]
  --background=RRGGBB[AA]
               specify foreground/background color in hexadecimal notation.
               6-digit (RGB) or 8-digit (RGBA) form are supported.
               Color output support available only in PNG and SVG.
  -V           display the version number and copyrights of the qrencode.
  [STRING]     input data. If it is not specified, data will be taken from
               standard input.

常用参数:

  • -t 指定输出二维码格式,支持PNG,EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8共9种图片或非图片格式,图片包括位图png和无损矢量图eps、svg共三种格式,满足你对非高清或高清画质的需求,输出为图片的时候需要结合-o接上文件名;而非图片格式的可以直接标准输出,其效果如下:
for type in ANSI ANSI256 ASCII ASCIIi UTF8 ANSIUTF8;do echo $type ;qrencode -t $type "a";done

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

  • -s 输出为图片时,指定每个模块的大小(默认3*3的dots),通过此选项可调整输出图片的大小
  • -l 指定二维码的纠错级别(从低L到中M到高H),貌似输出为ascii格式有用
  • -m 指定边缘的大小默认为4
  • -d 当输出格式为png时指定dpi值,值越大输出越清晰

安装

# centos如下,其他可自行google
sudo yum install -y qrencode
发布了23 篇原创文章 · 获赞 18 · 访问量 6560

猜你喜欢

转载自blog.csdn.net/qq_42491125/article/details/103002670