Python Pillow: Create a QRCode Image with Background Color

In this tutorial, we will use an example to show you how to create a qrcode image with different background color. You can create a new one by following our steps.

Python Pillow - Create a QRCode Image with Background Color - A Step Guide

1.Import qrcode

import qrcode

qrcode can be installed in this tutorial:

Python Pillow: Create a QRCode Image Using qrcode Library

2.Create qrcode image with different background color

qr = qrcode.QRCode(
    version=12,
    error_correction=qrcode.constants.ERROR_CORRECT_H,
    box_size=2,
    border=8
)
qr.add_data('test text')
qr.make()
img = qr.make_image(fill_color="red", back_color="#23dda0")

Here ‘test text’ is the content in qrcode image. We will use qr.make_image() to create a qrcode image with different background color.

3.Save qrcode image to file

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

Run this code, you will see this colored qrcode image.

Python Pillow - Create a QRCode Image with Background Color