Python Pillow: Create a QRCode Image with a Logo Image in Center

In this tutorial, we will use an example to show you how to create a qrcode image with a logo image in its center.

Python Pillow - Create a QRCode Image with a Logo Image in Center for Beginners

1.Open logo image using pillow

import qrcode
from PIL import Image

face = Image.open('data/src/lena.jpg')

2.Create a qrcode image

qr_big = qrcode.QRCode(
    error_correction=qrcode.constants.ERROR_CORRECT_H
)
qr_big.add_data('I am Lena')
qr_big.make()
img_qr_big = qr_big.make_image().convert('RGB')

3.Determine the position of qrcode image center

pos = ((img_qr_big.size[0] - face.size[0]) // 2, (img_qr_big.size[1] - face.size[1]) // 2)

4.Paste the logo image in the center of qrcode image

img_qr_big.paste(face, pos)
img_qr_big.save('data/dst/qr_lena2.png')

Run this code, you will see this qrcode.

Python Pillow: Create a QRCode Image with a Logo Image in Center