Skip to main content

A CLI tool to generate QR codes with custom colors and icons

Project description

QR Code Generator

PyPI version Python version License GitHub issues

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

  1. CLI Interface โ€” Command-line argument parsing via argparse with flexible input options
  2. QR Generation โ€” Leverages the qrcode library for reliable QR encoding
  3. Image Processing โ€” Uses Pillow (PIL) for image manipulation
  4. Watermarking โ€” Custom logo/watermark scaling and centering with transparency preservation
  5. 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 (not rgb(255, 87, 51))

QR code not scannable

  • Try increasing error correction level: --ec H
  • Increase QR code size: --size 600 or 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:

  1. Fork the repository on GitHub
  2. Create a feature branch: git checkout -b feature/your-feature-name
  3. Make your changes and commit: git commit -m "Add your feature"
  4. Write/update tests to cover your changes
  5. Push to your fork: git push origin feature/your-feature-name
  6. 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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qr_generator_cli-1.0.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qr_generator_cli-1.0.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

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

Hashes for qr_generator_cli-1.0.2.tar.gz
Algorithm Hash digest
SHA256 f9449086fdca28ea3eb5819055e6fd6724ec4aafd33b5387986fdb5f178867b6
MD5 0e79ebabdba992fb3103e78256c2fd11
BLAKE2b-256 a61bb7eb7651239a4ec58da47527a31a63f4a92a78c5717e683aece5c206514a

See more details on using hashes here.

File details

Details for the file qr_generator_cli-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for qr_generator_cli-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fdb07513c9f7a1f9fb1cf97a4b8942700b7c9a38fd1336e22840ed708d1aaa41
MD5 d70b1123f4965180bd7a92a79f5db63e
BLAKE2b-256 ccb7599f6a884be219354ea534b2ee2356291c88162874a24560b86c629af830

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page