Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate QR Code with python Code

2025-03-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to use python code to generate QR code, I believe that many inexperienced people do not know what to do. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

1. Can the QR code be used up?

Many people have scanned the QR code, and most people have the impression of a small black-and-white square. In fact, the QR code is a kind of coding that uses computer image processing technology and combined coding principle. It uses the image of black-and-white pixels to represent "1" and "0" in the binary system, and expresses its meaning through the arrangement and combination of points, so the essence of the QR code is to convert the data into a way of storage. So no matter who generates a QR code with the content of "multi-player movement, five gang up", the final output of the QR code is the same.

The key information of the QR code is as follows: as long as you can scan these five parts, you can scan the contents of the QR code, otherwise you can use your finger to block any part of it and try to scan it out.

So how much information can a QR code store at most? The QR code is limited in size, and the largest QR code is version 40 QR code 177 * 177. The QR code for the smallest version 1 is 21 * 21. If you use the largest QR code to store data, you can store 7089 numbers or 4296 letters, 23624bit data, as shown in the picture, can your phone scan it out? I finally found a reason to change my phone, and I can't even scan the QR code.

Version 40 QR code

Others worry about whether the QR code will run out and want to lead the times to pioneer the 3D code. Here we can calculate that the smallest version of the QR code is 21x21, with a total of 441 squares, each with only black or white options, minus the fixed number of 192 corner location boxes of the QR code. The QR code in 21x21 format has a combination of 2 to the 249th power, and this number has 75 digits. If the Chinese scan the code once a second every day, they can sweep for 1.479 billion years (700 million), and then Jia Yueting will return home.

two。 Generate a classic QR code with one line of code

Using python's MyQR library to make a QR code requires only one line of code, the first parameter input the contents of the QR code (not Chinese), and the second parameter input the saved QR code picture name to generate a QR code.

From MyQR import myqr as mq

Mq.run ('https://www.zhihu.com/people/hou-yu-wen-80',save_name='ewm.png')

If you want to generate a QR code with Chinese, you need to use the qrcode library to make it, and only one line of code can be generated.

Import qrcode

Qrcode.make ('I, Lu Benwei didn't hang up'). Save ('test.png')

Import qrcode

Qr = qrcode.QRCode (version=1,error_correction=qrcode.constants.ERROR_CORRECT_L,box_size=10,border=4,)

Qr.add_data ('I, Lu Benwei, didn't open it')

Qr.make (fit=True)

Img = qr.make_image (fill_color= "black", back_color= "white")

Img.save ('lbw.png')

Meaning of "" parameter:

Version: an integer with a value of 1 to 40 that controls the size of the QR code (the minimum value is 1, which is a 12 × 12 matrix). If you want the program to determine automatically, set the value to None and use the fit parameter.

Error_correction: controls the error correction function of QR code. You can take the following four constants.

ERROR_CORRECT_L: about 7% or less of errors can be corrected.

ERROR_CORRECT_M (default): about 15% or less of errors can be corrected.

ROR_CORRECT_H: about 30% or less of errors can be corrected.

Box_size: controls the number of pixels contained in each grid in the QR code.

Border: controls the number of squares contained in the border (the distance between the QR code and the image boundary) (the default is 4, which is the minimum specified by the relevant standards)

"

3. QR code with picture

Of course, the classic version of the QR code can not meet our use of x, here we can make the profile picture of our girlfriend into a QR code, invisible x is the most deadly.

From MyQR import myqr as mq

Mq.run ('https://www.weibo.com/u/5644764907',

Picture= "ycy.jpg"

Colorized=True

Save_name='ycy_code.png')

You only need to import the corresponding image in the picture parameter to generate a QR code with a background image. If the imported image is in gif format, the corresponding dynamic QR code will be generated.

Athlete basketball superstar 4. Can make parody / confession QR code

If you associate the QR code with other applications / websites, it will have a surprising effect. The following QR codes have special functions and can be enjoyed slowly.

Parody QR code to express love QR code after reading the above, do you know how to generate QR code with python code? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report