-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #274 from shashank-amireddy/master
Add custom logo feature for QR code generation
- Loading branch information
Showing
5 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# QR Code Generator with Logo | ||
|
||
## Description | ||
This Python script generates a QR code with a specified URL and overlays a logo onto it. It utilizes the `qrcode` library to generate the QR code and the `PIL` library for image processing to overlay the logo. | ||
|
||
## Prerequisites | ||
- `qrcode` library: You can install it via pip with the command `pip install qrcode`. | ||
- `PIL` library: You can install it via pip with the command `pip install pillow`. | ||
|
||
## How to Run the Script | ||
1. Ensure you have installed the required libraries mentioned above. | ||
2. Replace the `logo_path` and `url` variables with your desired logo path and target URL, respectively. | ||
3. Run the script. | ||
4. The script will generate a QR code image named `qr_with_logo.png` in the current directory. | ||
|
||
## Sample Use | ||
![QR Code with Logo](qr_with_logo.png) | ||
|
||
## Author | ||
[Shashank Reddy](https://github.com/shashank-amireddy) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import qrcode | ||
from PIL import Image | ||
|
||
|
||
#import requests | ||
|
||
# Load the logo image | ||
# Logo_link = 'https://cdn.pixabay.com/photo/2022/01/30/13/33/github-6980894_1280.png' | ||
# logo_response = requests.get(Logo_link, stream=True) | ||
# logo_response.raise_for_status() # Raise an exception for HTTP errors | ||
# logo_img = Image.open(logo_response.raw) | ||
|
||
''' | ||
if you want to take an image which is already hosted on web comment lines 18,19 and use the above method | ||
''' | ||
|
||
# Path to the logo image file on user's machine | ||
logo_path = "github-logo.png" | ||
logo_img = Image.open(logo_path) | ||
|
||
url = 'https://github.com/shashank-amireddy' | ||
|
||
# Ensure the logo has an alpha channel (transparency) | ||
logo_img = logo_img.convert("RGBA") | ||
|
||
# Resize the logo to fit within the QR code | ||
basewidth = 100 | ||
wpercent = basewidth / float(logo_img.size[0]) | ||
hsize = int(float(logo_img.size[1]) * float(wpercent)) | ||
logo_img = logo_img.resize((basewidth, hsize), Image.LANCZOS) | ||
|
||
# Generate QR code | ||
QRcode = qrcode.QRCode( | ||
error_correction=qrcode.constants.ERROR_CORRECT_H | ||
) | ||
QRcode.add_data(url) | ||
QRcode.make() | ||
|
||
# Create QR code image with a mode that supports color | ||
QRimg = QRcode.make_image(fill_color="black", back_color="white").convert("RGBA") | ||
|
||
# Calculate position to paste the logo | ||
logo_position = ( | ||
(QRimg.size[0] - logo_img.size[0]) // 2, | ||
(QRimg.size[1] - logo_img.size[1]) // 2 | ||
) | ||
|
||
# Paste the logo onto the QR code | ||
QRimg.paste(logo_img, logo_position, logo_img) | ||
|
||
# Save the final QR code image | ||
QRimg.save('qr_with_logo.png') | ||
print('QR code generated!') |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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