Create dynamic color QR code with Python

The two-dimensional codes we usually see are black and white, and the shape is not very beautiful. This article will teach you how to turn your file link into a beautiful QR code. You can enter your file by scanning the QR code on WeChat. The following are the processing steps in Python.

1. Download library

Run pip install myqr (windows operating system) in Anaconda Prompt. Note that the myqr library depends on Python3, which may not work properly in Python2.

2. Create a normal QR code

from MyQR import myqr  #Pay attention to case
myqr.run(words='https://mp.weixin.qq.com/s?__biz=MzIxMjA1NzQzMQ==&tempkey=MTA0OV91Q0Vla25GWHpjaWxYZEV2eHVBbGZGY2E0TmwtMF9hRFh1WVdTQUpaWURMMGZnZTAzQ0F1VmNiN2ZtcXpyRlpSMEI4TUFtbmV6Si00cmxZejdCdFRGRWh2X1FFcC1ic0RuUW5ZdUVDYmtOT3lncTJyZTR2YkcxQk42STFrNHp5aHpxWk5rS2M2QVJBUklGc3docVNYZzlJQ2RZVE5mdXFBQ0ZveERBfn4%3D&chksm=174aad19203d240fc38d47c4d8ba927a790345fb3f54c6d9629b705c14776d7426bea927d272#rd')  #Generate the first QR code
myqr.run(words='https://mp.weixin.qq.com/s?__biz=MzIxMjA1NzQzMQ==&tempkey=MTA0OV9KZUlBNkRjUWxJMGRnMnFneHVBbGZGY2E0TmwtMF9hRFh1WVdTQUpaWURMMGZnZTAzQ0F1VmNiN2ZtclZpdGtNSDhMdFdUT1kwTlAyenh6R2lObzF6eTFNa21SYzB0Vm93cDh1d3M3enpsYlFwcGFDckIzQjVjMl8ybE5Ca051NUNleHBxLXpSWTVMRXlIWXlHcjJaS1BfZ2M0b0xoV04zMWhvXzZBfn4%3D&chksm=174aad6c203d247a251c2510675cafcc3c71292dd116e704b8d729b08bb85ddbbd9a26e844be#rd')  #Generate the second QR code

**Code analysis: **

from this line of code is to load the library

The myqr line of code is to put the URL you want to turn into a QR code in (words=), it will turn the URL into a QR code, and you can load the URL with a scan. After I put the links of the two articles in the official account in Words, I ran the code to generate the following QR code. If you don’t believe it, you can use a long press to identify the QR code and you can automatically jump to the URL.

Isolated forest

Risk control modeling process

3. Generate patterned QR code

myqr.run(words='https://mp.weixin.qq.com/s?__biz=MzIxMjA1NzQzMQ==&tempkey=MTA0OV9wbzMwZzBpbFBPazFDNFN3eHVBbGZGY2E0TmwtMF9hRFh1WVdTQUpaWURMMGZnZTAzQ0F1VmNiN2ZtcmNjWEpxeksxQl9SR2xKNnJ6di1ycEdqajlLMlhfdk5QMlV0U3ZsRDVFVHVhQkxpMTMzU3dnMVhNazRuRHk2OVQ0Ym5Ca3RSSHJOZkkyWnVodkdXVEV4WnZnQmNnLWFmS2pPOEhZQUJLZFF3fn4%3D&chksm=174aad2c203d243ae99de72da7ef3a5478df442c2833157caba07f19456b098615b027573017#rd', 
   picture='Pikachu.jpg',colorized=True)  #Generate the first QR code
myqr.run(words='https://china.nba.com/', 
   picture='basketball.jpg',colorized=True)   #Generate the second QR code

**Code analysis: **

In addition to assigning values to the words parameter, the code this time also adds the picture and colorized parameters. I put the article link of Pikachu drawn with Python in the official account after words, the value after picture is the picture you want to add to the QR code, colorized=True is to adjust the color of the QR code from black and white to color (note: The picture and code keep the same path).

The function of the second sentence of code is exactly the same as the first sentence of code, except that the URL after words is replaced by the NBA official website, and the picture after picture is replaced by a basketball picture.

Run the code separately to generate the following two QR codes

Draw Pikachu with python

NBA official website

4. Create dynamic color QR code

myqr.run(words='https://china.nba.com/', 
   picture='Slam dunk.gif',version=1,brightness=1.0,level='H',colorized=True) #Generate the QR code on the left
myqr.run(words='https://baike.so.com/doc/5410236-5648317.html', 
   picture='Long.gif',version=1,brightness=1.0,level='H',colorized=True) #Generate the QR code on the right

**Code analysis: **

wrods parameter: the QR code points to the link (str), or it can be a string in the text, the first sentence of the code points to the NBA official website

Picture parameter: Combine the picture (str), combine the QR code with the picture passed in this parameter to generate a new picture, the first sentence of code is assigned as'slam dunk.gif'

Verson parameter: side length (int), optional, range 1-40, the larger the number, the larger the side length

Brightness parameter: image brightness (float), optional, the default value is 1.0

level parameter: error correction level (str), range L, M, Q, H, increasing from left to right, the default is H

colorized parameter: control color (bool), True is color, False is black and white

In addition to the parameters used in this article, there are save_name (output file name) and save_dir (storage location) two parameters in myqr.run, which are to set the name and memory address of the QR code image you want to store, the following two dynamic two-dimensional The code is the result of the above two sentences (note: some URLs may take a little longer to convert into a dynamic QR code, please be patient).

NBA official website

Bailongma Baidu Encyclopedia

This article is some of my insights after using myqr library, please correct me if there is any inappropriateness.

- end-

Recommended Posts

Create dynamic color QR code with Python
Gray-level co-occurrence matrix (with python code)
Speed up Python code with Cython
Python | Quickly test your Python code with Hypothesis
python requests.get with header
Getting started with Python(18)
Getting started with Python(9)
Play WeChat with Python
Getting started with Python(8)
Getting started with Python(4)
Web Scraping with Python
Getting started with Python (2)
Getting started with python-1
Python SMS bombing code
Getting started with Python(14)
Getting started with Python(7)
Getting started with Python(17)
Getting started with Python(15)
Getting started with Python(10)
Getting started with Python(11)
Getting started with Python(6)
Getting started with Python(3)
Getting started with Python(12)
Getting started with Python(5)
Getting started with Python (18+)
Getting started with Python(13)
Getting started with Python(16)