Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to generate QR Code Image with Python

Shulou Source: shulou.com Published: 2022-06-01 19:56:34 09月19日 Update

Editor to share with you how to use Python to generate QR code images, I believe that most people do not understand, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Preface

Recently inadvertently saw someone on the Internet using Python to write dozens of lines of code to generate image verification code, feel very tedious, here recommend two methods for all friends, use 4 lines of Python code to generate verification code.

Captcha library

Step 1: install the captchaa library

Pip install captcha

Step 2: generate image verification code with 3 lines of code

From captcha.image import ImageCaptchaimage = ImageCaptcha () .generate_image ("9527") image.show ()

The effect is as follows:

You can also generate random image verification codes within a specified range of characters. The sample code is as follows:

From captcha.image import ImageCaptchafrom random import randintlist = [0, 1, 2, 3, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, g, h, i, j, k, lump, m' 'nasty,' oiled, 'paired,' qpressed, 'rusted,' sworn, 'tweeted,' upright, 'vested,' wicked,'x-shaped, 'yearly,' zoned, 'awful,' baked, 'clocked,' dusted, 'eyed,' Fried, 'Globe,' Hilly, 'Ivy,' Jacks, 'Knights,' L' Data = 'for i in range (4): data + = list [randint (0,62)] image = ImageCaptcha (). Generate_image (data) image.show ()

Step 1: install the graphic-verification-code library

Pip install graphic-verification-code

Because I failed to download pip all the time, I went to the official website to download it. I also failed for a long time, and the speed was terrible.

Step 2: 4 lines of code to generate image verification code

Import gvcodes, v = gvcode.generate () # sequence unpack s.show () # display the generated CAPTCHA picture print (v) # print CAPTCHA string

The random generation effect is as follows:

The above is all the contents of the article "how to generate QR Code Image with Python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Generation verification image code code generation article 2D QR code content character effect tedious ugly not so preface available in picture most string official Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno macOS MariaDB Apple Microsoft