HelloGitHub-LITTLECHIEH
This is HelloGitHub’s “explain open source project” series. Today, I recommend a Python open source qrcode generation project — qrcode
Introduce a,
Qr code 1.1
Two-dimensional Code is also known as two-dimensional bar Code, the common TWO-DIMENSIONAL Code is QR Code, QR full name Quick Response. It is a super popular coding method on mobile devices in recent years. Two-dimensional code can be seen everywhere in our daily life. We can use it to pay, browse websites and so on. Why is it so popular? Here are a few features:
- Large amount of information can be stored: up to 1850 capital letters or 2710 numbers or 1108 bytes or more than 500 Chinese characters.
- Strong fault tolerance: it has error correction function, which makes the two-dimensional barcode can be correctly read when local damage is caused by perforation and defacement, and the information can still be recovered when the damaged area reaches 30%.
- High reliability of decoding: it is much lower than ordinary barcode decoding error rate of two per million, the error rate is not more than one in ten million.
- Laser recognition.
For example, we are now common public two-dimensional code, he took advantage of the fault tolerance of two-dimensional code, in the middle of the two-dimensional code to join the public icon. Although the picture in the middle covers part of the real data of the TWO-DIMENSIONAL code, it does not affect the data to be transmitted by the two-dimensional code because of its strong fault tolerance.
1.2 Composition of qr code
A picture is worth thousands of words, good here the basic knowledge of two-dimensional code is introduced.
1.3 Generate a TWO-DIMENSIONAL code library
Two-dimensional code is a very convenient carrier to transmit information, but the two-dimensional code like the black and white above feels very lack of “soul”. Here is today’s hero: Qrcode
This is a two-dimensional code generator written by Python, support to generate GIF dynamic, image two-dimensional code, make your two-dimensional code interesting.
Project address: github.com/sylnsfar/qr…
Second, qrCode library advantages
Why do I need to use this QR code generator to generate qr codes?
- Easy to use: quick to get started, just 2 lines of code to get started!
- Add pictures in the TWO-DIMENSIONAL code: can let the user through the two-dimensional code in the picture, preliminary understanding of the two-dimensional code is related to what. (The QR code has been added with the LOGO of HG)
- Various ways of use: There are the following three ways of use
- Command-line mode
- Importing a file (import)
- Executable file
- Use it right: I don’t want you to feel, I want me to feel
funny
Three, quick start
The demo environment
Operating system: Windows | Python version: 3.5
3.1 installation
We installed it using Python’s PIP package management tool:
pip install myqr
Copy the code
Note: You may need to upgrade PIP by running the PIP install –upgrade PIP command
Once installed, you can use it directly from the command line! The following explains the generation method of the two-dimensional code one by one
3.2 Common TWO-DIMENSIONAL code
First, an ordinary QR code is generated
-
Open the CMD
-
Type the command
myqr https://github.com -n helloword.png Copy the code
Parameter -n: indicates the file name of the QR code
This will result in a TWO-DIMENSIONAL code image, the generated image is saved in the current directory, then you can modify the default directory by passing parameters.
3.3 Color QR Code
- Prepare an image for the table of contents (square images work best)
-
Change the image name to github.jpg (suffix depends on your photo format)
-
On the command line, enter:
myqr https://github.com -n mypicture.png -p github.jpg -c Copy the code
Parameters:
-n
: Specifies the name of the GENERATED QR code-p
: Indicates the image added to the QR code. JPG, GIF, and PNG formats are supported-c
: Specifies whether to generate a color QR code. If not, the color is black and white by default- See appendix below for more parameters
3.4 Dynamic TWO-DIMENSIONAL Code
The steps are the same as the method of color TWO-DIMENSIONAL code, but attention should be paid to:
- Add the image to GIF
- Change the suffix of the GENERATED TWO-DIMENSIONAL code to GIF
Fourth, the appendix
4.1 MyQR parameters
Common parameters sorted from official documents are as follows:
-n
: Specifies the name of the GENERATED QR code-p
: QR code to join the picture, support.jpg
,.gif
,.png
,.bmp
format-c
: Specifies whether to generate a color QR code. If not, the color is black and white by default-v
: Controls the edge length. The range is 1 to 40. The larger the number, the larger the edge length-l
: Control error correction level, the range is L, M, Q, H ascending from left to right-d
: Controls the storage location of the output QR code-con
: Used to adjust the contrast of the image, 1.0 means the original image, a smaller value means lower contrast, more and vice versa. The default is 1.0-bri
: Used to adjust the brightness of the picture, other usage and value-con
The same
4.2 CMD Changing the drive letter
There is a trick to opening the command line, which can quickly switch CMD to the desired directory, avoiding the trouble of switching drive letters:
-
Use file management to find the target folder
-
Enter CMD in the top address bar and ‘Enter’
- Pit for switching drive letters: Switching drive letters directly will fail
4.3 Introduction to classification of QR codes
Two-dimensional code has the following categories
- Black and white and color codes
- Black and white yards
- The color code
- Fusion and visual code
- Fusion code: it is to fuse the content with the TWO-DIMENSIONAL code to make them into a whole. The picture is composed of the two-dimensional code, and the two-dimensional code is a part of the picture. This is more suitable for the use of simple structure of the picture or text to beautify the main content
- Visual code: Take the picture as the background, and then build many special points on the picture, these points will not affect the visual effect of the background
- Art TWO-DIMENSIONAL code, is the two-dimensional code of each “code eye” according to the designer’s idea to analyze, disassemble, merge, and then fill in the “code eye” area with some small material elements, and finally form a unique two-dimensional code.
Five, the last
That’s all for this article. I believe you have a better understanding of qr codes. And have a certain understanding of the common parameters of qrcode library, then quickly to generate an interesting, ‘soul’ TWO-DIMENSIONAL code!
Have fun library, but don’t know how to use, look dry? Let us know and join us. Our vision: “Let the people who are interested in open source no longer fear, the initiator of open source project no longer alone.”
Vi. Reference materials
- Tips | still using black and white QR codes? Too weak! Teach you something new!
- PDF Talk about QR Code
- QRcode
“Explain Open Source Project series” — let the people who are interested in open source projects not be afraid, let the initiator of open source projects not be alone. Follow along as you discover the joys of programming, use, and how easy it is to get involved in open source projects. Welcome to leave a message to contact us, join us, let more people fall in love with open source, contribute to open source ~