Skip to content

Commit

Permalink
Merge pull request #274 from shashank-amireddy/master
Browse files Browse the repository at this point in the history
Add custom logo feature for QR code generation
  • Loading branch information
DhanushNehru authored Oct 2, 2024
2 parents 80c7d7e + 43064a6 commit 5a12f82
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
20 changes: 20 additions & 0 deletions QR with Logo/README.md
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)
Binary file added QR with Logo/github-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions QR with Logo/qr.py
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!')
Binary file added QR with Logo/qr_with_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ More information on contributing and the general code of conduct for discussion
| Playlist Exchange | [Playlist Exchange](https://github.com/DhanushNehru/Python-Scripts/tree/master/Playlist%20Exchange) | A Python script to exchange songs and playlists between Spotify and Python.
| PNG TO JPG CONVERTOR | [PNG-To-JPG](https://github.com/DhanushNehru/Python-Scripts/tree/master/PNG%20To%20JPG) | A PNG TO JPG IMAGE CONVERTOR.
| QR Code Generator | [QR Code Generator](https://github.com/DhanushNehru/Python-Scripts/tree/master/QR%20Code%20Generator) | This is generate a QR code from the provided link |
| QR Code with logo | [QR code with Logo](https://github.com/DhanushNehru/Python-Scripts/tree/master/QR%20with%20Logo) | QR Code Customization Feature
| Random Color Generator | [Random Color Generator](https://github.com/DhanushNehru/Python-Scripts/tree/master/Random%20Color%20Generator) | A random color generator that will show you the color and values! |
| Remove Background | [Remove Background](https://github.com/DhanushNehru/Python-Scripts/tree/master/Remove%20Background) | Removes the background of images. |
| Rock Paper Scissor 1 | [Rock Paper Scissor 1](https://github.com/DhanushNehru/Python-Scripts/tree/master/Rock%20Paper%20Scissor%201) | A game of Rock Paper Scissors.
Expand Down

0 comments on commit 5a12f82

Please sign in to comment.