Skip to main content

QRCode XColor

Note: This does not work with the qrcode version 7.3.1 in pypi. pypi will not allow git sources in the setup.py requirments so mush be manually installed

Install qrcode from master branch

pip install git+https://github.com/lincolnloop/python-qrcode.git@8a37658d68dae463479ee88e96ee3f1f53a16f54

This library recreates a few of the moduledrawers classes already found in https://github.com/lincolnloop/python-qrcode.

This was done to greatly speed up the generation of creating colored qrcodes, as well as supporting for different colors and styles for the location marker in the corners.

Using these custom classes you do lose support for the full features of the color_mask argument in the original QRCode library like having the colors be a gradient across the qrcode.

I chose for speed over having that feature with still getting full color and transparency support of the qrcode.

All supported module drawers:

from qrcode_xcolor import (
    XStyledPilImage,
    XSquareModuleDrawer,
    XGappedSquareModuleDrawer,
    XCircleModuleDrawer,
    XRoundedModuleDrawer,
    XVerticalBarsDrawer,
    XHorizontalBarsDrawer
)

Here are some examples of the speed difference:

import time

import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers import GappedSquareModuleDrawer, RoundedModuleDrawer
from qrcode.image.styles.colormasks import SolidFillColorMask

from qrcode_xcolor import XStyledPilImage, XGappedSquareModuleDrawer, XRoundedModuleDrawer

st = time.time()
qr = qrcode.QRCode()
qr.add_data("https://example.com")
img = qr.make_image(
    image_factory=StyledPilImage,
    color_mask=SolidFillColorMask(
        front_color=(59, 89, 152),
        back_color=(255, 255, 255),
    ),
    module_drawer=GappedSquareModuleDrawer(),
    eye_drawer=RoundedModuleDrawer(),
    embeded_image_path='docs/gitlab.png',
)
img.save("qrcode_color_mask.png")
print(f"qrcode color_mask: {time.time() - st:.4f}s")


st = time.time()
qr = qrcode.QRCode()
qr.add_data("https://example.com")
# The 4th value in all the colors is the opacity the color should use (0=clear <--> 255=solid)
img = qr.make_image(
    # Custom image factory
    image_factory=XStyledPilImage,
    back_color=(255, 255, 255, 255),  # Background color with opacity support
    module_drawer=XGappedSquareModuleDrawer(
        front_color=(59, 89, 152, 255),
    ),
    eye_drawer=XRoundedModuleDrawer(
        front_color=(255, 110, 0, 255),
        inner_eye_color=(65, 14, 158, 255),  # Only valid with the eye_drawer
    ),
    embeded_image_path='docs/gitlab.png',  # Still supports embedding logos in the middle
)
img.save("qrcode-xcolor.png")
print(f"qrcode-xcolor: {time.time() - st:.4f}s")

From this test we get the results (exact timings will vary but the difference is always there):

qrcode color_mask: 0.5071s

qrcode color_mask

qrcode-xcolor: 0.0430s

qrcode-xcolor

Metadata

Release files for qrcode-xcolor 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qrcode-xcolor 0.1.1
File Size Uploaded
qrcode-xcolor-0.1.1.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qrcode-xcolor 0.1.1
File Interpreter ABI Platform
qrcode_xcolor-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.3 kB

Release files / qrcode-xcolor-0.1.1.tar.gz

Download URL qrcode-xcolor-0.1.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7dfbf971b3b2f593261a51db477c12ac6ac17f360572bed012f346fce94f2b5f
BLAKE2b-256 checksum
How to use checksums
88f6610fbf13f4861195d5452ed741194a5e464b028f62bd9e6ae899c4a69982
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / qrcode_xcolor-0.1.1-py3-none-any.whl

Download URL qrcode_xcolor-0.1.1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c19ce53c5a54087b8cede6b992ca4e362552e49f81d1969f98ababb2952a6bf3
BLAKE2b-256 checksum
How to use checksums
a04ae2a93b30cf673545005b9143ff461cacc24bbd0d412d16e338dfbd80f381
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page