Member-only story

Add Logo in any QR Code using Python

Python Coding
2 min readJan 2, 2025

--

1. Importing Required Libraries

from PIL import Image
import qrcode
  • PIL.Image: Used for image processing (part of the Pillow library).
  • qrcode: Library for generating QR codes.

2. Taking Input for QR Code Data

data = input("Enter the data for the QR code: ")
  • Prompts the user to input the data (e.g., a URL, text, or other content) to be encoded into the QR code.

3. Creating the QR Code

qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)
qr.add_data(data)
qr.make(fit=True)
  • QRCode: Creates a QR code object.
  • error_correction=qrcode.constants.ERROR_CORRECT_H: Adds error correction, allowing the QR code to be readable even if parts of it are obscured (e.g., by a watermark).
  • add_data(data): Adds the user input data to the QR code.
  • make(fit=True): Automatically sizes the QR code to fit the data.

4. Generating the QR Code Image

qr_image = qr.make_image(fill_color="black", back_color="white").convert('RGBA')
  • make_image(fill_color, back_color)

--

--

Python Coding
Python Coding

Written by Python Coding

Learn python tips and tricks with code I Share your knowledge with us to help society. Python Quiz: https://www.clcoding.com/p/quiz-questions.html

No responses yet