Python5 lines of code to generate characteristic QR codes

The myqr library of python has the function of generating QR code, you can realize the characteristic QR code with just a few lines of code, come and try!

  1. First need to install myqr library

win+R open the command line
pip install myqr

2. After installation, you can happily program

The step is to import the library first, and then use the run function. Note that there are several important parameters in the function.

parameter effect
words QR code content or link
picture Custom QR code background image, support .jpg, .png, .bmp, .gif format, the default is black and white
colorized QR code background color, the default is False, that is black and white
version The size of the QR code, the range is [1,40]
level Two-dimensional code error correction level, the range is {L,M,Q,H}, H is the highest level, default.
contrast Contrast, the higher the value, the higher the contrast, the default is 1.0
brightness Brightness, the higher the value, the higher the brightness, the default is 1.0, the value is often the same as the contrast
save_name QR code name, the default is qrcode.png
save_dir QR code path, default is the program working path

The main things you need to change here are the words parameter, the picture parameter, and the colorized parameter are generally set to True. Finally, the save_name and save_dir parameters are required to determine the QR code name and path.
Generally, the contrast parameter, version parameter, level parameter, and brightness parameter can be kept as default, and you don't care about it.

  • The simplest QR code
from MyQR import myqr
myqr.run(words='https://blog.csdn.net/weixin_46530492',
         save_name='try.jpg')

Insert picture description here

  • QR code with custom background

Increase the parameters appropriately

from MyQR import myqr
myqr.run(words='https://blog.csdn.net/weixin_46530492',
         picture='C:/Users/lenovo/Pictures/109951164593784012.jpg',
         save_name='panxi.png',
         save_dir='pictures',
         colorized=True)

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

  • Custom dynamic QR code
from MyQR import myqr
myqr.run(words='https://blog.csdn.net/weixin_46530492',
         picture='C:/Users/lenovo/Pictures/20200518095751683.gif',
         save_name='xinyuanjieyi.gif',
         save_dir='pictures',
         colorized=True)

The codes are almost the same, the difference is that the imported local pictures need to be in GIF format, and the save_name parameter also needs to be in .gif format.
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
The code has almost no skills, a lot of time is actually spent on finding pictures, go and try!

Guess you like

Origin blog.csdn.net/weixin_46530492/article/details/106974530