Skip to content

Sometimes it can be useful to have a python code to generate custom qr code. This repo is for that. When I'll need to create custom qr code I will use and update this repo consequently.

License

Notifications You must be signed in to change notification settings

tsua0002/custom_qr

Repository files navigation

Custom QR Code Generator 🐍

A flexible and customizable QR code generator that allows you to create beautiful QR codes with different design styles.

Features

  • Multiple design styles: Google, Multicolored, and Custom
  • Customizable text (title, subtitle, footer)
  • Command-line interface for easy use
  • Configuration file support
  • Fallback font handling
  • Proper error handling and logging

Installation & Setup

Using pipenv (Recommended)

  1. Install pipenv if you haven't already:
pip install pipenv
  1. Clone the repository and navigate to it:
git clone <repository-url>
cd custom_qr
  1. Install dependencies using pipenv:
pipenv install
  1. Activate the virtual environment:
pipenv shell

Using pip (Alternative)

If you prefer not to use pipenv, you can install dependencies directly:

pip install -r requirements.txt

Usage

Important: Always Run Inside pipenv Shell

Make sure you're in the virtual environment before running commands:

pipenv shell

Basic Usage

Generate a QR code with the default design (custom):

# Inside pipenv shell
python main.py --url="https://example.com"

Design Examples

  1. Google-style QR code:
# Inside pipenv shell
python main.py --url="https://example.com" \
               --design="google" \
               --title="Google" \
               --subtitle="Review" \
               --footer="TEAM <3"
  1. Multicolored QR code:
# Inside pipenv shell
python main.py --url="https://www.linkedin.com/in/thomas-suau-92932889/" \
               --design="multicolored" \
               --title="My LinkedIn" \
               --subtitle="Review" \
               --footer="Thomas"
  1. Custom QR code with gradient:
# Inside pipenv shell
python main.py --url="https://example.com" \
               --design="custom" \
               --title="Your Title" \
               --subtitle="Your Subtitle" \
               --footer="scan to visit example.com"

Using Configuration Files

You can also use a JSON configuration file:

# Inside pipenv shell
python main.py --config="sample_config.json"

Example configuration file (sample_config.json):

{
    "url": "https://example.com",
    "design": "google",
    "output": "my_google_qr.png",
    "title": "My Company",
    "subtitle": "Visit Us",
    "footer": "TEAM <3"
}

Command Line Arguments

The following arguments are available:

  • --url: URL to encode in the QR code (required)
  • --design: Design style for the QR code (choices: "google", "multicolored", "custom", default: "custom")
  • --output: Output filename (will be saved in the outputs directory)
  • --title: Title text for the QR code
  • --subtitle: Subtitle text for the QR code
  • --footer: Footer text for the QR code
  • --config: Path to a configuration file

Project Structure

custom_qr/
├── outputs/          # Generated QR codes are saved here
├── fonts/           # Required fonts for text rendering
│   ├── CaviarDreams.ttf
│   ├── ORGANICAL.ttf
│   └── PatchworkStitchlings.ttf
├── main.py          # Main entry point
├── qr_generator.py  # QR code generator classes
├── requirements.txt # Python dependencies for pip
├── Pipfile         # Python dependencies for pipenv
└── sample_config.json

Fonts

The generator uses custom fonts for better aesthetics. If the fonts are not available, it will fall back to the default system font.

Default font paths:

  • fonts/CaviarDreams.ttf
  • fonts/PatchworkStitchlings.ttf
  • fonts/ORGANICAL.ttf

Logging

The application logs information and errors to both the console and a log file (qr_generator.log). This helps with debugging and tracking the generation process.

Error Handling

The application includes proper error handling for common issues:

  • Invalid URLs
  • Unsupported designs
  • Missing configuration files
  • Font loading errors
  • File system errors

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Run

pipenv shell
> pipenv install --ignore-pipfile

Example :

> python3 custom_qr.py

Everything is happening on the python code.

Check data variable.

Info about files

custom_qr.py : One color around the qr, and text message.

multicolored_qr.py: Close to Google graphics around QR code with Text.

About

Sometimes it can be useful to have a python code to generate custom qr code. This repo is for that. When I'll need to create custom qr code I will use and update this repo consequently.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages