A CLI tool to generate QR codes with custom colors and icons
Project description
QR Code Generator
A powerful, easy-to-use Python package for generating professional QR codes with customizable styling, watermark/logo support, and multiple output formats.
Overview
QR Code Generator enables you to quickly create QR codes from URLs or plain text with full control over appearance and branding. Perfect for marketing materials, product packaging, event management, and more.
Key Highlights:
- ๐จ Fully customizable colors and styling
- ๐ท๏ธ Built-in watermark/logo support with automatic scaling
- ๐ฆ Easy installation from PyPI
- ๐ฅ๏ธ Both CLI and Python API
- ๐พ Multiple output formats (PNG, JPG, JPEG)
- ๐ง Simple, intuitive interface
Features
- โ Generate QR codes from URLs or plain text
- โ Customize size, foreground/background colors, and error correction level
- โ Add watermark/logo with automatic centering and scaling
- โ Save to PNG/JPG/JPEG formats
- โ Command-line interface (CLI) for quick generation
- โ Python API for programmatic use
- โ Packaged and published on PyPI
- โ
Project metadata and build configuration via
pyproject.toml - โ Supports error correction levels (L, M, Q, H)
- โ Automatic output directory creation
Requirements
- Python >= 3.8
- Dependencies:
qrcode[pil],Pillow
Installation
From PyPI (Recommended)
pip install qr-generator-cli
From GitHub
Install the latest development version from the repository:
pip install git+https://github.com/Ahmed122000/QR-Code-Generator.git
Development Install
Clone the repository and install in editable mode:
git clone https://github.com/Ahmed122000/QR-Code-Generator.git
cd QR-Code-Generator
pip install -e .
Quick Start
Using the CLI
The simplest way to generate QR codes:
# Basic: generate and save to qrcode.png
qr "https://example.com" --output qrcode.png
# With custom styling
qr "https://example.com" --size 800 --fg "#1d3557" --bg "#f1faee" --ec H
# Add a watermark/logo
qr "https://example.com" --output qrcode.png --watermark assets/logo.png --watermark-scale 0.25
# Plain text input
qr "Hello, World!" --output text-qr.png
# High error correction
qr "https://example.com" --size 600 --ec H --output secure-qr.png
Using the Python API
For programmatic QR code generation:
from qr_generator import QRGenerator
# Create a QR code generator instance
gen = QRGenerator()
# Generate and save a QR code
gen.make_qr(
data="https://example.com",
output_path="qrcode.png"
)
# With custom styling
gen.make_qr(
data="https://example.com",
output_path="styled_qr.png",
size=800,
fg_color="#1d3557",
bg_color="#f1faee",
error_correction="H"
)
# With watermark/logo
gen.make_qr(
data="https://example.com",
output_path="branded_qr.png",
watermark_path="assets/logo.png",
watermark_scale=0.25
)
CLI Options
Usage: qr [OPTIONS] DATA
Arguments:
DATA The URL or text to encode in the QR code
Options:
--output, -o Output file path (default: qrcode.png)
--size QR code size in pixels (default: 400)
--fg, --foreground Foreground color as hex code (default: #000000)
--bg, --background Background color as hex code (default: #FFFFFF)
--ec, --error-correction Error correction level: L, M, Q, H (default: M)
--watermark Path to watermark/logo image file
--watermark-scale Watermark scale relative to QR code (default: 0.2)
--help Show help message
Configuration Reference
Error Correction Levels
| Level | Recovery | Use Case |
|---|---|---|
| L | ~7% | Low-traffic environments |
| M | ~15% | Standard use (recommended) |
| Q | ~25% | Partially obscured codes |
| H | ~30% | Highly damaged/outdoor use |
Color Formats
Colors should be specified as hexadecimal values:
#000000(black)#FFFFFF(white)#FF5733(custom colors)
Examples
Example 1: Simple QR Code
from qr_generator import QRGenerator
gen = QRGenerator()
gen.make_qr("https://github.com/Ahmed122000", output_path="github_qr.png")
Example 2: Branded QR Code
from qr_generator import QRGenerator
gen = QRGenerator()
gen.make_qr(
data="https://yourcompany.com",
output_path="company_qr.png",
size=600,
fg_color="#2C3E50",
bg_color="#ECF0F1",
watermark_path="company_logo.png",
watermark_scale=0.3,
error_correction="H"
)
Example 3: Batch Generation
from qr_generator import QRGenerator
import csv
gen = QRGenerator()
# Read URLs from CSV and generate QR codes
with open("urls.csv", "r") as f:
reader = csv.DictReader(f)
for row in reader:
gen.make_qr(
data=row["url"],
output_path=f"output/{row['name']}_qr.png",
size=500,
fg_color="#1d3557",
bg_color="#f1faee"
)
How It Works
Architecture
- CLI Interface โ Command-line argument parsing via
argparsewith flexible input options - QR Generation โ Leverages the
qrcodelibrary for reliable QR encoding - Image Processing โ Uses Pillow (PIL) for image manipulation
- Watermarking โ Custom logo/watermark scaling and centering with transparency preservation
- Output โ Supports PNG, JPG, and JPEG formats with high quality
Process Flow
User Input (URL/Text)
โ
Validation & Normalization
โ
QR Code Generation (qrcode library)
โ
Watermark Processing (if provided)
โ
Image Conversion (if needed)
โ
File Output
Project Structure
QR-Code-Generator/
โโโ src/
โ โโโ main.py # CLI entry point
โ โโโ qr_generator.py # Core QR generation logic
โ โโโ utils.py # Utility functions
โโโ examples/
โ โโโ basic.py # Simple QR generation
โ โโโ with_logo.py # Watermark/logo example
โ โโโ batch_generate.py # Batch processing example
โโโ assets/
โ โโโ output/ # Sample output directory
โ โโโ logo.png # Sample logo for examples
โโโ tests/ # Unit tests
โโโ pyproject.toml # Package configuration
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ .gitignore # Git ignore rules
Troubleshooting
Common Issues
ImportError: No module named 'qrcode'
pip install qrcode[pil] Pillow
PermissionError: Permission denied creating output directory
- Ensure you have write permissions in the target directory
- Try creating the output directory manually:
mkdir -p output
Watermark not displaying
- Verify the watermark file path exists and is readable
- Use PNG format with transparency for best results
- Check watermark-scale is between 0.1 and 0.5
Invalid color format
- Ensure colors are specified as hex values:
#RRGGBB - Example:
#FF5733(notrgb(255, 87, 51))
QR code not scannable
- Try increasing error correction level:
--ec H - Increase QR code size:
--size 600or higher - Ensure sufficient contrast between foreground and background colors
Version History
v1.0.0
- โจ Initial release
- ๐ฆ Published to PyPI as
qr-generator-cli - ๐จ Full customization support
- ๐ท๏ธ Watermark/logo feature
- ๐ฅ๏ธ CLI and Python API
For detailed release notes, see CHANGELOG.md (if available).
Contributing
We welcome contributions! Here's how to get started:
- Fork the repository on GitHub
- Create a feature branch:
git checkout -b feature/your-feature-name - Make your changes and commit:
git commit -m "Add your feature" - Write/update tests to cover your changes
- Push to your fork:
git push origin feature/your-feature-name - Open a Pull Request with a clear description of your changes
Development Workflow
# Install in development mode
pip install -e ".[dev]"
# Run tests
python -m pytest
# Run linting
pylint src/
# Format code
black src/
Reporting Issues
Found a bug? Please open an issue with:
- Clear description of the problem
- Steps to reproduce
- Expected vs. actual behavior
- Python version and OS information
Performance Considerations
- QR Code Size: Larger QR codes (800x800px) take slightly longer to generate but are easier to scan
- Watermark Processing: Watermarked codes take ~10-20% longer due to image compositing
- Batch Operations: For generating 100+ codes, consider using threading or async patterns
Security Notes
- Input Validation: URLs and text are validated before QR encoding
- File Permissions: Output files are created with standard user permissions
- No External Calls: All processing is local; no data is sent to external services
Limitations
- Maximum data capacity: ~2953 bytes (depends on error correction level)
- Watermarks should be <= 30% of QR code size for optimal scanability
- Recommended minimum QR code size: 200x200 pixels
License
This project is licensed under the MIT License โ see the LICENSE file for details.
You are free to use, modify, and distribute this software, provided you include the original copyright notice and license.
Acknowledgments
- Built with qrcode
- Image processing powered by Pillow
- Inspired by the need for simple, professional QR code generation
Support
- ๐ Documentation: See examples and features above
- ๐ Bug Reports: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
Author
Ahmed122000
GitHub: @Ahmed122000
Made with โค๏ธ for the open-source community
If you find this project useful, please consider giving it a โญ on GitHub!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qr_generator_cli-1.0.2.tar.gz.
File metadata
- Download URL: qr_generator_cli-1.0.2.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9449086fdca28ea3eb5819055e6fd6724ec4aafd33b5387986fdb5f178867b6
|
|
| MD5 |
0e79ebabdba992fb3103e78256c2fd11
|
|
| BLAKE2b-256 |
a61bb7eb7651239a4ec58da47527a31a63f4a92a78c5717e683aece5c206514a
|
File details
Details for the file qr_generator_cli-1.0.2-py3-none-any.whl.
File metadata
- Download URL: qr_generator_cli-1.0.2-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdb07513c9f7a1f9fb1cf97a4b8942700b7c9a38fd1336e22840ed708d1aaa41
|
|
| MD5 |
d70b1123f4965180bd7a92a79f5db63e
|
|
| BLAKE2b-256 |
ccb7599f6a884be219354ea534b2ee2356291c88162874a24560b86c629af830
|