Created
August 21, 2024 14:11
-
-
Save Sinnnnak/e5bf8aeba1497dfbad60b8f210755070 to your computer and use it in GitHub Desktop.
Qr Code Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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