Python Two-dimensional code generator

Source: Internet
Author: User

Zhou Xiao Dong Jianxu home QR code. PNG

 Zhou Xiao Dong blog Home qr code. PNG

Now, we can see two-dimensional code everywhere in our lives. What good is it? It has the advantages of large information capacity, high reliability, can express Chinese characters and images of many kinds of text information, security strong security and so on.

What we generate is usually on the computer. If you get a mobile device, the most used is the sweep code. Entering a URL in the mobile device browser is obviously not easy to scan the QR code.

That's it:

 

Python has a qrcode library that easily generates QR codes. It is now common to use the Pillow module instead of PIL when it comes to using the Python image library. Installation is simple:

Pip Install Pillow

Installing QRCode is also similar:

Pip Install QRCode

It can also be generated quickly in Python in the following ways:

Import= Qrcode.make ('Some datahere')

More advanced settings require the introduction of the QRCode class in Python:
Example code 1:

Import= QRCode. QRCode (version=2, error_correction=qrcode.constants.error_correct_l, box_size=10, border=1) qr.add_data ( "python hobby tribe Snake") qr.make (Fit== qr.make_image () img.save("  snake_qrcode.png")

The resulting result is:

 

The results of the scan are:

 

The parameter version indicates the size of the generated QR code, the value range is 1 to 40, the minimum size 1 will generate 21 * 21 of the two-dimensional code matrix, version every 1, the resulting QR code will add 4 unit size, for example, version is 2, then generate 25 * 25 Size of the two-dimensional code.

The parameter error_correction specifies the fault tolerance coefficients for the two-dimensional code, respectively, with the following 4 coefficients:
error_correct_l:7% Loadline can be fault-tolerant
error_correct_m:15% Loadline can be fault-tolerant
error_correct_q:25% Loadline can be fault-tolerant
error_correct_h:30% Loadline can be fault-tolerant

The parameter box_size represents the pixel size of each lattice in the QR code.
The parameter border indicates how wide the bounding box is (by default, 4).

Example code 2 (generates a QR code with an icon):

ImportQRCode fromPILImportIMAGEQR=QRCode. QRCode (Version=2, Error_correction=Qrcode.constants.ERROR_CORRECT_H, Box_size=10, Border=1) Qr.add_data ("Python Hobby tribe, the home of Python lovers") Qr.make (Fit=True) img=qr.make_image () img= Img.convert ("RGBA") img_w, Img_h=Img.sizefactor= 3Size_w= Int (img_w/factor) Size_h= Int (Img_h/factor) icon= Image.open ("Snake.png") Icon_w, Icon_h=icon.sizeifIcon_w >Size_w:icon_w=Size_wifIcon_h >Size_h:icon_h=Size_hicon=icon.resize ((Icon_w, Icon_h), Image.antialias) W= Int ((IMG_W-ICON_W)/2) H= Int ((IMG_H-ICON_H)/2) Img.paste (icon, (W, h), icon) Img.save ("Snake_love_qrcode.png")

In this way, the film will be

 

Generate two-dimensional code:

 

If it is a download URL, it can be downloaded directly after scanning.
Put it on Jenkins, and each build will be downloaded directly to the phone.

Python Two-dimensional code generator

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.