Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Domains/Frontend/MiniProjects/Qr Code Generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
**Contributor:** MeghPatel-007

# 📱 QR Code Generator

A simple and beginner-friendly **Python project** that generates QR codes from any link or text. It can optionally shorten long URLs using the **TinyURL API** for cleaner, shareable QR codes! 🔗📸

---

## 📑 Table of Contents

1. [✨ Features](#-features)
2. [🎯 How to Use](#-how-to-use)
3. [📂 Folder Structure](#-folder-structure)
4. [📸 Screenshots](#-screenshots)
5. [📝 License](#-license)

---

## ✨ Features

- 🔗 Generate QR codes from links or text
- ✂️ Optional **URL shortening** via TinyURL API
- 💾 Automatically saves QR code images to your local folder
- 🧱 Custom file naming for better organization
- 💡 Beginner-friendly and well-commented Python script

---

## 🎯 How to Use

1. Clone the repository and navigate to the project folder.
2. Install dependencies:
```bash
pip install qrcode requests
python qr_generator.py

--
## 📂 Folder Structure

QR-Code-Generator/
├─ qr_code_generator.py # Main Python script
├─ qr_codes/ # Folder to store generated QR codes
├─ qr_code_generator_shorten_url.py #for generating short url qr codes
└─ README.md # This README file

---

## 📝 License

This project is licensed under the **MIT License**. See the LICENSE file for details.

---

## 🙏 Thank You

Thanks for checking out my QR Code Generator project!
I hope you enjoy generating QR codes and find it useful. 🔗✨

Feel free to leave feedback or suggestions for improvement!
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import qrcode
import os
import requests

def shorten_url(long_url):
"""
Shortens a URL using the TinyURL API.
"""
api_url = f"http://tinyurl.com/api-create.php?url={long_url}"
response = requests.get(api_url)
if response.status_code == 200:
return response.text
else:
raise Exception("Failed to shorten URL")

# Get user input
data = input("Enter the link: ")
shorten = input("Do you want to shorten the URL? (y/n): ").lower()

if shorten == "y":
try:
data = shorten_url(data)
print(f"Shortened URL: {data}")
except Exception as e:
print(e)
print("Proceeding with original URL...")

name = input("Enter the name of the file (without extension): ")

# Create QR code
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(data)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")

# Save to 'qr_codes' folder relative to this script
save_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "qr_codes")
os.makedirs(save_path, exist_ok=True)
file_path = os.path.join(save_path, f"{name}.png")
img.save(file_path)

print(f"✅ QR code generated and saved to {file_path}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import qrcode
import os

# Get user input
data = input("Enter the link or text: ")
name = input("Enter the name of the file (without extension): ")

# Create QR code
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(data)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")

# Save to a folder named 'qr_codes' relative to this script
save_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "qr_codes")
os.makedirs(save_path, exist_ok=True) # creates folder if it doesn't exist

# Save the image
file_path = os.path.join(save_path, f"{name}.png")
img.save(file_path)

print(f"QR code generated and saved to {file_path}")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import requests
Loading