Full text dry goods, suggested collection after use yo!
directory
- Common QR code
- Art QR code with pictures
- Dynamic two-dimensional code
- Function common parameter list
Today, I would like to share with you a small project of two lines of Python code to show the SAO operation, to generate their own exquisite TWO-DIMENSIONAL code, including ordinary two-dimensional code, artistic two-dimensional code with pictures and dynamic two-dimensional code. First wave effect picture:
Common QR code
Art QR code with pictures
Dynamic two-dimensional code
Ok, now it’s time to see how to use two lines of code to generate your own QR code.
To generate two-dimensional code in Python, you need to call MYQR third-party library, which can be said to be tailored for two-dimensional code. Call the run function of the module can directly generate the desired two-dimensional code.
.
Common QR code
To generate ordinary TWO-DIMENSIONAL code, we only need to pass the link to generate two-dimensional code to words parameter in run. For example, we need to generate two-dimensional code on the main interface of 360 browser: the website is “hao.360.com/”. Run the following code:
from MyQR import myqr
myqr.run(words='https://hao.360.com/')Copy the code
Now you can find the generated.png qr code in the default folder of the application.
.
Art QR code with pictures
When generating the art TWO-DIMENSIONAL code with pictures, we need to add the “picture” parameter on the basis of the original program, which means the background picture of the two-dimensional code we want to set. Use colorized=True parameter to set the background of the picture to color, otherwise, the default generated picture will be black and white background.
We can also name the QR code using the save_name parameter.
It is important to note that in order to avoid image formatting errors, the format of the named QR code needs to be the same as the background image format.
For example, we take the picture “mtsc_body15.png” as the background to generate two-dimensional code. The generated QR code is named “qr1.png”
The code is as follows:
from MyQR import myqr
myqr.run(words='https://hao.360.com/',
picture='Sources/mtsc_body15.png',
save_name='qr1.png',
colorized=True)
Copy the code
The generated TWO-DIMENSIONAL code effect is as follows:
.
Dynamic two-dimensional code
In fact, the dynamic two-dimensional code and the artistic two-dimensional code generation method with pictures is similar, we just need to change the background picture to GIF, the generated two-dimensional code picture format is also changed to GIF. Take this GIF of the beautiful Noyi Niigaki as an example:
The code is as follows:
from MyQR import myqr
myqr.run(words='https://hao.360.com/',
picture='Sources/gakki.gif',
save_name='qr4.gif',
colorized=True)
Copy the code
OK, now look at the effect, this wave operation will definitely show the students face.
.
Function common parameter list
In addition to the above mentioned parameters, there are many internal parameters of the run function can be used to generate the TWO-DIMENSIONAL code, here the big Wolf and everyone to share the common parameters of the run function:
I think so. Yeah.Thumb up attentionHey!
Follow my wechat official account“Grey Wolf Cave Owner”The background to reply“Python notes”To get fromGet started to master the full set of Python notes and Python common knowledge functions quick guide!
Big bad Wolf is looking forward to progress with you!