Skip to main content

Custom QRCode Modules

Project description

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

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

qrcode-xcolor-0.1.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

qrcode_xcolor-0.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file qrcode-xcolor-0.1.1.tar.gz.

File metadata

  • Download URL: qrcode-xcolor-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for qrcode-xcolor-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7dfbf971b3b2f593261a51db477c12ac6ac17f360572bed012f346fce94f2b5f
MD5 3d40e934b8888e4f80a37d600ae85391
BLAKE2b-256 88f6610fbf13f4861195d5452ed741194a5e464b028f62bd9e6ae899c4a69982

See more details on using hashes here.

File details

Details for the file qrcode_xcolor-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for qrcode_xcolor-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c19ce53c5a54087b8cede6b992ca4e362552e49f81d1969f98ababb2952a6bf3
MD5 de2fa2d9a226028dba7e4bcec822b0c9
BLAKE2b-256 a04ae2a93b30cf673545005b9143ff461cacc24bbd0d412d16e338dfbd80f381

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