How to use a line of code to achieve dynamic two-dimensional code production?
It is easy to use and can be installed directly through PIP
pip3 install myqr
Copy the code
Once the installation is complete, you can generate the QR code you want. Right! It’s that simple…
Common QR code
Simply execute the following code
# myQR qr code content
>myqr http://weixin.qq.com/r/khy5oY7EN9NIrcrC90mA
Copy the code
The corresponding qrcode image will be generated in the current directory. The default name is qrcode.png.
To modify the name or path of the generated TWO-DIMENSIONAL code, run the following command:
- -n: indicates the name of a user-defined QR code
- -d: indicates the path of user-defined TWO-DIMENSIONAL code
For example: generate a PYTHon3x.jpg qr code image in the root directory of drive E
myqr http://weixin.qq.com/r/khy5oY7EN9NIrcrC90mA -n Python3X.jpg -d E:\
Copy the code
For the TWO-DIMENSIONAL code, you can customize its size and error tolerance and error correction ability.
- -v: defines the size of the QR code. The value ranges from 1 to 40. The default size depends on the input content.
- -L: define the two-dimensional code error correction rate, that is, the two-dimensional code is blocked part is still recognized, there are four grades, respectively L(7%), M(15%), Q(25%), H(30%). The default is the highest grade H
Such as the generation of size is 10, error correction rate is M level of two-dimensional code
myqr http://weixin.qq.com/r/khy5oY7EN9NIrcrC90mA -v 10 -l M
Copy the code
Generative Art TWO-DIMENSIONAL code
Sometimes in order to attract everyone’s attention, the effect of ordinary TWO-DIMENSIONAL code will be inadequate. So you can use the form of art TWO-DIMENSIONAL code, the way of generation is very simple.
For example, I found a picture of Peppa Pig on the Internet
If you want to combine Peppa Pig with our QR code, you can do it through the -p command, which is also very simple, still a line of code.
myqr http://weixin.qq.com/r/khy5oY7EN9NIrcrC90mA -p peiqi.jpg
Copy the code
But, it doesn’t seem to be what we wanted. It’s black and white…
In this case, another command, -c, is used for coloring the image.
myqr http://weixin.qq.com/r/khy5oY7EN9NIrcrC90mA -p peiqi.jpg -c
Copy the code
After the implementation, did you find the effect is much better?
If you need to change the image contrast, or brightness. This can be done in one of two ways
- -con: Modifies the image contrast. The default value is 1.0
- -BRI: Changes the brightness of the picture. The default value is also 1.0
Generate dynamic TWO-DIMENSIONAL code.
Dynamic two-dimensional code
Art TWO-DIMENSIONAL code although much more beautiful, but still can not achieve our purpose of installing X, so, you can come to a dynamic two-dimensional code.
In the same way as the above art QR code, the only difference is that the picture must be GIF. The default is also black and white, so you need to add -c
The code is as follows:
myqr http://weixin.qq.com/r/khy5oY7EN9NIrcrC90mA -p pig.gif -n Python3X.gif -c
Copy the code
Effect:
EXE file
If you don’t have Python3 on your computer at this point, or don’t want to install qrcode. An EXE program is also provided here. This program is packaged with PyInstaller. In the process of testing, it was found that the generation of two-dimensional code is sometimes faster and sometimes slower. The cause is unknown..
Use method, also not very complicated, just need to exe file at the same directory, create an info.txt file, enter the corresponding parameters in the inside, if you need to generate art TWO-DIMENSIONAL code, also need to add your image or GIF file in the same directory.
The contents of info.txt are as follows:
# Content of QR code
words=http://weixin.qq.com/r/khy5oY7EN9NIrcrC90mA
# size
v=11
Image (GIF) path
p=pig.gif
Print the name of the QR code
n=Python3X.gif
# color
C
Copy the code
It should be noted that the comments in the above content are only for explanation. The annotated Chinese characters need to be deleted during use, otherwise errors will be compiled.
After the configuration is complete, run myqr.exe to generate the TWO-DIMENSIONAL code you need in the current directory. If the two-dimensional code cannot be generated normally, run exe in CMD.
What is not clear place, welcome message!