https://github.com/xtream1101/qrcode-xcolor
https://github.com/xtream1101/qrcode-xcolor
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/xtream1101/qrcode-xcolor
- Owner: xtream1101
- License: mit
- Created: 2022-12-26T03:49:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-26T04:43:05.000Z (over 3 years ago)
- Last Synced: 2025-06-18T15:19:35.607Z (about 1 year ago)
- Language: Python
- Size: 77.1 KB
- Stars: 4
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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 must be manually installed_
**Install qrcode from master branch**
```bash
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:
```python
from qrcode_xcolor import (
XStyledPilImage,
XSquareModuleDrawer,
XGappedSquareModuleDrawer,
XCircleModuleDrawer,
XRoundedModuleDrawer,
XVerticalBarsDrawer,
XHorizontalBarsDrawer
)
```
Here are some examples of the speed difference:
```python
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-xcolor: 0.0430s
```
