Skip to main content

Generate and customize QR codes

Project description

custom_qr Library

PyPI versionLicenseMaintenance

The custom_qr library enables the generation and customization of QR codes with various options.

Example 1

Example 2

Example 3

Example 4

Installation

  1. Install the library:
pip install custom_qr
  1. Verify Installation:
pip list

Note: It is recommended to use a virtual environment.

Usage

  1. Import the library:
from custom_qr import QrCode
from custom_qr import (
    ERROR_CORRECTION_LEVEL_H,
    ERROR_CORRECTION_LEVEL_Q,
    ERROR_CORRECTION_LEVEL_M,
    ERROR_CORRECTION_LEVEL_L
)

Note: Error correction level constants are optional. 2. Create a QR Code:

qr = QrCode()
matrix, version = qr.generate("https://www.qrcode.com/")

To specify a version and/or error correction level:

qr = QrCode()
matrix, version = qr.generate("https://www.qrcode.com/", version=6, error_correction=ERROR_CORRECTION_LEVEL_Q)
  • Default Error Correction Level: Q (recovers 25% of data).
    • Default Version: Automatically calculated based on data size.
  1. Print on Console:
qr.print_qr_console(matrix)

Note: Console output is not scannable. 4. Get Image Version:

img = qr.create_qr_image(matrix)
  1. Display On Screen:
qr.display_qr(img)
  1. Save Image:
qr.create_image_file(img, filename="qr.png")

Note: Default filename is "qr.png".

Custom QR Code Features

Color Usage in QR Codes

  • Adding Text: Be cautious, as text may cover modules and hinder scannability.
  • Contrast: Ensure sufficient contrast between blocks, background, and fixed patterns.
  • Complexity: Avoid overly complex color schemes to maintain scanner compatibility.

Test QR codes with various devices to ensure scannability.

Customization Options

  1. Background Color: Default is white.
background = (255, 255, 255)
qr.create_qr_image(matrix, background)
  1. Block/Modules Style Options: Default size is 10, type square, and color black. Example:
block_style = {
    "size": 10,
    "type": 0,
    "color": [(0, 0, 0), (255, 0, 0)]  # Black and Red
}
qr.create_qr_image(matrix, block_style)
  • size: Size of each module in pixels.
    • type: Shape of modules:
      • 0: Square blocks.
      • 1: Circular blocks.
    • color: List of RGB tuples for module colors.
  1. Custom Circular Modules:
block_style = {
    "size": 10,
    "type": 1,  # Circular
    "color": [(0, 0, 0), (255, 0, 0)]  # Black and Red
}
qr.create_qr_image(matrix, block_style)

Finder and Alignment Pattern Colors

  • Finder Pattern: Default color is the same of modules first color.
finder_style = {"color": (0, 0, 0)}
qr.create_qr_image(matrix, finder_style)
  • Alignment Pattern: Defaults to the finder pattern's color if not specified.
alignment_style = {"color": (0, 0, 0)}
qr.create_qr_image(matrix, alignment_style)

Adding Custom Text

Overlay custom text on the QR code, but be mindful of potential readability issues:

  • Text Style Options:
    • color: RGB tuple for text color.
    • size: Font size (currently only "small" is enabled).
    • bot: Bottom margin in blocks.
    • left: Left margin in blocks.
    • orientation:
      • 0: Write text from left.
      • 1: Write text from right.

Example:

text_style = {
    "color": (6, 123, 194),
    "size": "small",
    "bot": 10,
    "left": 3,
    "orientation": 0
}
text = "CUSTOM"
img = qr.create_qr_image(matrix)
qr.write_text(img, text, text_style, background, block_style["size"])

Write from Right:

text_style = {
    "color": (6, 123, 194),
    "size": "small",
    "bot": 10,
    "left": 30, # Left margin has to be greater than text width
    "orientation": 1  # Adjusted to write from right
}
text = "CUSTOM"
img = qr.create_qr_image(matrix)
qr.write_text(img, text, text_style, background, block_style["size"])

Note: Use higher versions and error correction levels to maintain validity when adding text. If the text is too large, write_text() will return None.

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

custom_qr-0.9.5.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

custom_qr-0.9.5-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file custom_qr-0.9.5.tar.gz.

File metadata

  • Download URL: custom_qr-0.9.5.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for custom_qr-0.9.5.tar.gz
Algorithm Hash digest
SHA256 2fba97f194f7a173b0eb2faa9f3ec2a518056fd5a114a5d7d83b95b519cf1b08
MD5 87c61eed5eedd8dc7d863a2bdf75d873
BLAKE2b-256 637107e5401f826473e797884358ed2c801bf40a972724dd5a580ca30c794c7f

See more details on using hashes here.

File details

Details for the file custom_qr-0.9.5-py3-none-any.whl.

File metadata

  • Download URL: custom_qr-0.9.5-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for custom_qr-0.9.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1fcb46dce126fbd0b510852aa026d1351c00c747543ef93cc3f481d12b2f90d0
MD5 337a6dbd0dbbc40f2e2a4fa94ca75e07
BLAKE2b-256 4be2ddc2425728bc966e8ca300e43f1e2db538a06fd6aa1362eb838cb05d13cb

See more details on using hashes here.

Supported by

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