One, foreword
Common QR code is QR CodeCode, QR full name is Quick Response, is a super popular way of coding on mobile devices in recent years. Its structure is as follows:
The main features are as follows:
- Symbol specification: From version 1(21×21) to Version 40(177×177), 4 symbols are added on each side (i.e., the square black and white dots that form the QR code).
- Large information capacity: it can store 7089 numeric characters or 4296 alphabetic characters or 2953 8-bit byte characters or 1817 Chinese characters
- Strong error correction capability: data can be recovered even if part of the code becomes dirty or damaged. Level L can correct about 7% of the data code words, level M about 15% of the data code words, level Q about 25% of the data code words, and level H about 30% of the data code words
- Can be read from any direction: QR code can be read quickly from 360° in any direction. Through the QR code in the three location pattern, can help QR code is not affected by the background style, to achieve fast and stable reading
Second, the MyQR
Python has a very interesting library, MyQR, which can not only make a variety of beautiful QR codes, but also generate dynamic color QR codes.
MyQR can generate common QR codes, artistic QR codes (black and white or color), dynamic QR codes (black and white or color)
1. The effect is shown in the figure:
2. Implementation steps
The first step is to install the MyQR library
Install MyQR library directly using pip3 install MyQR (or MyQR). Note that MyQR relies on Python3 and may not work properly in a Python2 environment.
pip install MyQR -i pypi.douban.com/simple –trusted-hostpypi.douban.com
The library provides two ways to use it, either directly from the command line or by importing it using import, where you can set more personalization.
Step 2 refer to the code
From MyQR import MyQR import OS version, level, qr_name = myqr.run(words="https://www.baidu.com", # Version =1, # set error tolerance level='H', # set error correction level=' L ', 'M ',' Q ', 'H', Colorized =True, # Contrast =1.0, # to adjust the contrast of the image, 1.0 means the original image, a smaller value means a lower contrast, whereas a larger one means a lower contrast. Save_name ="3.gif", # save the name of the file, Save_dir =os.getcwd() # control position)Copy the code
If you want to use the Pytho file, you can use the Pytho file. If you want to use the Pytho file, you can use the Pytho file.
You can see GIF images in Pycharm without moving. You can see them in the folder
I’ll give you a GIF to try your hand
MyQR is really very good to use, the only drawback is that it does not support Chinese!! It only supports the following characters:
- Numbers 0 through 9
- English letters of upper and lower case
- Commonly used English punctuation and Spaces
Here is the end, Python basic introduction, crawler, data analysis and other learning materials to share, more Exciting Python content, pay attention to me.