Python Pillow: Create a QRCode Image Using qrcode Library

In this tutorial, we will introduce how to create a qrcode using python pillow and qrcode library.

Python Pillow - Create a QRCode Image Using qrcode Library

1.Install pillow and qrcode library

pip install qrcode
pip install pillow

2.Creata a qrcode

import qrcode

img = qrcode.make('test text')

print(type(img))
print(img.size)
# <class 'qrcode.image.pil.PilImage'>
# (290, 290)

Here ‘test text‘ is the content in qrcode.

3.Save qrcode as to image

img.save('data/dst/qrcode_test.png')

Run this code, you will see this qrcode image:

Python Pillow - Create a QRCode Using qrcode Library

We also can use opencv to decode qrcode. Here is a tutorial:

Detect and Decode a QRCode Image Using cv2.QRCodeDetector() in Python OpenCV