Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions develop/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@
# Enable installed plugins. Add the name of each plugin to the list.
PLUGINS = ["netbox_qrcode"]

import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers import GappedSquareModuleDrawer
from qrcode.image.styles.colormasks import RadialGradiantColorMask
from PIL import ImageColor

# Plugins configuration settings. These settings are used by various plugins that the user may have installed.
# Each key in the dictionary is the name of an installed plugin and its value is a dictionary of settings.
PLUGINS_CONFIG = {
Expand Down Expand Up @@ -239,6 +245,19 @@
'label_edge_right': '0mm',
'with_text': False,
'with_qr': True,

# Styled QR image with radial gradient, gapped squares and embedded image
'qr_error_correction': qrcode.constants.ERROR_CORRECT_H,
'qr_image_kwargs': {
'image_factory': StyledPilImage,
'module_drawer': GappedSquareModuleDrawer(),
'color_mask': RadialGradiantColorMask(
back_color=ImageColor.getrgb("#ffffff"),
center_color=ImageColor.getrgb("#6642d3"),
edge_color=ImageColor.getrgb("#386bf1")
),
'embedded_image_path': "/opt/netbox/netbox/media/image-attachments/Netbox_Icon.png",
},
},

'device_7': {
Expand Down
1 change: 1 addition & 0 deletions develop/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
volumes:
- ./configuration.py:/opt/netbox/netbox/netbox/configuration.py
- ../docs/img/Netbox_Icon_Example.png:/opt/netbox/netbox/media/image-attachments/Netbox_Icon_Example.png
- ./Netbox_Icon.png:/opt/netbox/netbox/media/image-attachments/Netbox_Icon.png
- ../netbox_qrcode:/source/netbox_qrcode
tty: true
worker:
Expand Down
10 changes: 8 additions & 2 deletions netbox_qrcode/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@
# text: Text to be included in the QR code.
# **kwargs: List of parameters which properties the QR code should have. (e.g. version, box_size, error_correction, border etc.)
def get_qr(text, **kwargs):
qr = qrcode.QRCode(**kwargs)
qr_kwargs = {key: value for key, value in kwargs.items() if key != 'image_kwargs'}
qr = qrcode.QRCode(**qr_kwargs)
qr.add_data(text)
qr.make(fit=True)
img = qr.make_image()

if 'image_kwargs' in kwargs:
img = qr.make_image(**kwargs['image_kwargs'])
else:
img = qr.make_image()

img = img.get_image()
return img

Expand Down