Python generates two-dimensional code

Source: Internet
Author: User

Practice using Python to write two-dimensional code applet;

Need to install Python's QR code library--QRCode

Pip Install QRCode

The code is as follows:

#Coding=utf-8ImportQRCode
#a = Qrcode.make (' http://www.baidu.com ') #默认生成的二维码#a.save (' QR code _ Baidu. png ')qr=QRCode. QRCode (Version=1, Error_correction=QRCode. Error_correct_q, Box_size=4, Border=2) Qr.add_data ('http://www.baidu.com/') Qr.make (Fit=True) img= Qr.make_image (fill_color='Yellow', back_color='Blue') Img.save ('Two-dimensional code _ Baidu. PNG')

The parameter version indicates the size of the generated two-dimensional code, the value range is 1 to, the 40 smallest size 1 will generate 21 * 21 a QR code, version each increase 1 , the resulting QR code will be added to the 4 dimension,

For version example 2 , the resulting 25 * 25 two-dimensional code.

The parameter error_correction specifies the fault tolerance coefficients for the two-dimensional code, respectively, with the following 4 coefficients:

    1. ERROR_CORRECT_L: 7% of Loadline can be fault tolerant

    2. ERROR_CORRECT_M: 15% of Loadline can be fault tolerant

    3. ERROR_CORRECT_Q: 25% of Loadline can be fault tolerant

    4. ERROR_CORRECT_H: 30% of Loadline can be fault tolerant

box_sizethe parameter represents the pixel size of each lattice in the QR code.

borderThe parameter indicates how much the border's lattice thickness is (by default 4 ).

The resulting QR code is as follows:

QR code generated by default:

Set the QR code generated by the dimension color:

Python generates two-dimensional code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.