Skip to content

Instantly share code, notes, and snippets.

@Sinnnnak
Created August 21, 2024 14:11
Show Gist options
  • Select an option

  • Save Sinnnnak/e5bf8aeba1497dfbad60b8f210755070 to your computer and use it in GitHub Desktop.

Select an option

Save Sinnnnak/e5bf8aeba1497dfbad60b8f210755070 to your computer and use it in GitHub Desktop.
Qr Code Generator
import qrcode
from PIL import Image
# The URL you want the QR code to open
url = 'https://el-mojtaba.com/daily-verse'
# Create a QR code instance with custom settings
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H, # High error correction for design
box_size=10,
border=2,
)
# Add data
qr.add_data(url)
qr.make(fit=True)
# Customize colors (e.g., change the fill and background colors)
img = qr.make_image(fill_color="blue", back_color="white").convert("RGBA")
img.save("daily-verse.png")
# Load and prepare the logo
logo = Image.open("daily-verse.png").convert("RGBA")
logo = logo.resize((50, 50)) # Resize logo to fit the QR code center
# Create a new image with a white background to paste the QR code onto
base = Image.new('RGBA', img.size, (255, 255, 255, 255))
base.paste(img, (0, 0))
# Position for the logo
logo_position = (
(base.size[0] - logo.size[0]) // 2,
(base.size[1] - logo.size[1]) // 2
)
# Paste the logo onto the QR code image with the logo as a mask
base.paste(logo, logo_position, logo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment