There are QR codes everywhere in life. Simple QR code generation can be operated by importing qrcode or myqr/
For example, to make a simple QR code with a link to the official website, take GitHub as an example, first try using qrcode
import qrcode
qrcode.make('https://github.com').save('..//github.png') # 创建保存
qrcode.make('https://github.com').show() # 展示
You can generate a simple two-dimensional code, and run it as follows
(at this time, the two-dimensional code is not set for error tolerance, error correction level, color brightness, background, contrast and other parameters)
If we want to generate a personalized photo as the background How to make dynamic QR codes and improve the error tolerance and accuracy of QR codes through Python?
Take GitHub as an example, try with myqr
First import the MyQR package and the os standard library
from MyQR import myqr
import os
Choose a dynamic GIF picture you like, put it in the same project as the py file, set the path,
set the address, error tolerance rate, error correction level and other parameters and save, the code is as follows
myqr.run(
words='https://github.com',
version=10, # 设置容错率
level='H', # 纠错水平,L、M、Q、H,从左到右依次升高
picture='uuu.gif',
brightness=1, # 用来调节图片的亮度
colorized=True, # 黑白(False);彩色(True)
contrast=1, # 用以调节图片的对比度
save_name="p3.gif",
save_dir=os.getcwd() # 保存
)
This animated picture is about to be combined with the QR code.
We can press Ctrl+Shift+F10 in pycharm to run and get the following