Skip to content

Commit

Permalink
version 3 of the python file
Browse files Browse the repository at this point in the history
  • Loading branch information
rnddave committed May 14, 2024
1 parent 7ceec1f commit 0c4cb9c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions python-v3/qr-gen-v3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import qrcode
from PIL import Image

def generate_qr_with_logo(url, logo_path, output_path):
# Create a basic QR code
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=10,
border=4,
)
qr.add_data(url)
qr.make(fit=True)

# Generate the QR code image
qr_img = qr.make_image(fill_color="black", back_color="white").convert('RGB')

# Open the logo image
logo = Image.open(logo_path)

# Calculate the size of the logo
qr_width, qr_height = qr_img.size
logo_size = qr_width // 5
logo = logo.resize((logo_size, logo_size), Image.ANTIALIAS)

# Calculate the position to paste the logo
logo_pos = ((qr_width - logo_size) // 2, (qr_height - logo_size) // 2)

# Paste the logo onto the QR code
qr_img.paste(logo, logo_pos, mask=logo)

# Save the resulting QR code with the logo
qr_img.save(output_path)

# Example usage
generate_qr_with_logo(
url='https://www.example.com',
logo_path='logo.png',
output_path='qrcode_with_logo.png'
)

0 comments on commit 0c4cb9c

Please sign in to comment.